kamal setup vs kamal deploy

How to Fix the “docker: command not found” Error When Deploying Ruby on Rails Apps to a Fresh DigitalOcean Droplet Using Kamal

You’ve configured your Rails app, set up your deploy.yml file, and you’re ready to deploy to your shiny new DigitalOcean droplet using Kamal. You runย kamal deployย with anticipation, only to be met with a frustrating error: “docker: command not found.” Sound familiar? Whether you’re deploying your first MVP or scaling an established application, getting your deployment infrastructure right from the start saves countless hours down the line.

This common deployment roadblock stops countless developers in their tracks during their first Kamal deployment. The good news? You’re not alone, and the solution is straightforward once you understand what’s happening behind the scenes. In this comprehensive guide, I’ll walk you through exactly why this error occurs and show you multiple proven solutions to get your Rails application deployed successfully.

Understanding the Root Cause: Why Docker Is Missing

Before we dive into solutions, let’s understand what’s actually happening when you encounter this error. When you run kamal deploy on a fresh DigitalOcean droplet, Kamal attempts to execute Docker commands on your remote server. However, a brand new droplet typically doesn’t have Docker pre-installedโ€”it’s just a vanilla Ubuntu (or other Linux distribution) server waiting for configuration.

Kamal connects to servers via SSH and attempts to install Docker on any server missing it using get.docker.com, but this only happens when running kamal setup, not during kamal deploy. This is where most developers trip up. They skip the crucial kamal setup command and jump straight to deploying, assuming Kamal will handle everything automatically.

The error message you’re seeingโ€””bash: line 1: docker: command not found”โ€”is your server literally telling you it can’t find the Docker executable in its system PATH. The error typically appears with exit status 127, which specifically indicates a command not found error in Unix systems.

The Critical First Step: Run kamal setup Before kamal deploy

The most elegant and recommended solution is to use Kamal’s built-in server provisioning command. This is exactly what Kamal was designed to handle for you.

What kamal setup Actually Does

The kamal setup command sets up dependencies on your application server, installs Docker if missing, builds your container image locally, pushes it to your registry, pulls the image onto your application server, and generates SSL certificates via Let’s Encrypt. It’s essentially your server’s initialization process.

Here’s what happens step-by-step when you run this command:

  1. Kamal establishes an SSH connection to each server listed in your deploy.yml
  2. It checks whether Docker is installed on the remote machine
  3. If Docker is missing, it automatically installs it using the official installation script
  4. It configures Docker to start automatically on system boot
  5. It sets up Kamal proxy (the HTTP router) to handle incoming traffic
  6. It prepares the environment for your first deployment

How to Run kamal setup Correctly

Before running kamal setup, make absolutely sure you’ve committed all your changes to git. Kamal uses the latest commit hash for image names, and if you don’t commit first, your deployment may ship an old image.

This command will take several minutes to completeโ€”significantly longer than a regular kamal deploy. Don’t worry, this is normal. You’re essentially provisioning an entire server from scratch.

During the process, you’ll see output indicating:

  • Docker installation progress
  • Image building and pushing to your registry
  • Kamal proxy configuration
  • Your application container starting up

Once kamal setup completes successfully, your application should be live and accessible at your configured domain or server IP address.

Solution 2: Manually Installing Docker on Your Droplet

If you prefer more control or need to install Docker separately from Kamal’s automated process, you can manually install Docker on your DigitalOcean droplet before attempting deployment. This approach gives you visibility into exactly what’s being installed and how.

Step-by-Step Manual Docker Installation

Connect to your droplet via SSH:

First update your package index and install prerequisites like apt-transport-https, ca-certificates, curl, gnupg, and lsb-release, then add Docker’s official GPG key and set up the stable repository.

Verify Your Docker Installation

After installation completes, verify that Docker is running properly:

If you see the “Hello from Docker!” message, your installation is successful and you can proceed with kamal deploy.

Configure Non-Root User Access (Recommended)

For security best practices, you should create a dedicated deployment user rather than using root:

Update your config/deploy.yml to use this user:

Solution 3: Using DigitalOcean’s Docker 1-Click Droplet

DigitalOcean offers a streamlined alternativeโ€”creating a droplet with Docker pre-installed. This eliminates the installation step entirely.

Creating a Docker-Ready Droplet

When creating your droplet in the DigitalOcean control panel:

  1. Click “Create” โ†’ “Droplets”
  2. Under “Choose an image,” select the “Marketplace” tab
  3. Search for “Docker” in the search box
  4. Select “Docker on Ubuntu”
  5. Choose your droplet size (minimum 1GB RAM recommended)
  6. Select your datacenter region
  7. Add your SSH keys for authentication
  8. Click “Create Droplet”

The Docker 1-Click installation includes Docker CE version 20.10.7 or later and Docker Compose, making it ideal for developers and small-to-medium businesses.

Once your Docker-enabled droplet is created, you can skip directly to kamal deploy without needing kamal setup, since Docker is already installed and running.

Troubleshooting: When Docker Installation Fails

Even with the correct approach, you might encounter issues. Here are solutions to common problems:

Issue: Permission Denied Error

If you see “permission denied while trying to connect to the Docker daemon socket,” your user lacks Docker permissions.

Solution:

Issue: Docker Service Not Starting

If Docker installs but won’t start:

Issue: Kamal Can’t Find Docker After Installation

Sometimes the PATH variable doesn’t update immediately.

Solution:

Issue: SSH Connection Failures During Setup

Kamal requires SSH access to servers using root by default, authenticated by your SSH key, and root access via SSH is needed for Docker installation.

Solution: Verify your SSH configuration in config/deploy.yml:

Test SSH connectivity manually:

Best Practices for Kamal Deployments on DigitalOcean

1. Always Use kamal setup for Fresh Servers

Make it a habit: fresh server equals kamal setup first, deploy second. This single practice will save you countless headaches.

2. Commit Before Deploying

Kamal versioning relies on git commit hashes. Always commit your changes before running any Kamal commands.

3. Start with Adequate Resources

Ensure you have enough RAM on your server; insufficient memory can cause the system to go into swap during deployment, making it too slow and causing deployment timeouts. Start with at least a 1GB droplet for small applications. Once your deployment infrastructure is running smoothly, learn how Ruby on Rails services power scalable SaaS applications for long-term growth and sustainability.

4. Configure Your Deploy.yml Properly

Here’s a minimal but complete configuration:

5. Secure Your Server Immediately

Kamal only installs Docker and doesn’t harden your instance; you need to set up a firewall to block all ports except those necessary for your app, and fail2ban to prevent brute force attacks.

Basic firewall setup:

Understanding the Kamal Deployment Workflow

To prevent future issues, let’s clarify the complete deployment workflow:

For First-Time Deployment:

  1. Configureย config/deploy.ymlย with your server details
  2. Set up yourย .kamal/secretsย file with credentials
  3. Commit all changes to git
  4. Runย kamal setupย (installs Docker, sets up everything)
  5. Your app is now live

For Subsequent Deployments:

  1. Make your code changes
  2. Commit changes to git
  3. Runย kamal deployย (Docker already installed)
  4. Changes go live with zero downtime

f you’re new to Rails command line tools, mastering Rails CLI commands will help you navigate deployment workflows more efficiently.

Comparison: Different Approaches to Docker Installation

Method

Setup Time

Automation Level

kamal setup

5-10 minutes

Fully automated

Manual Installation

10-15 minutes

Manual

Docker 1-Click Droplet

3-5 minutes

Semi-automated

Pre-configured Server

Varies

Manual

When to Use Each Approach

Use kamal setup when:

  • You’re deploying to a fresh server for the first time
  • You want Kamal to handle everything automatically
  • You’re following standard Kamal workflows
  • You trust Kamal’s installation process

Use manual installation when:

  • You need specific Docker versions or configurations
  • You’re managing multiple servers with infrastructure-as-code tools
  • Your organization has specific security requirements
  • You want to understand each installation step

Use Docker 1-Click droplets when:

  • You’re deploying multiple applications to different servers
  • You want to minimize initial setup time
  • You’re comfortable with DigitalOcean’s pre-configured Docker version
  • You plan to manage Docker independently of Kamal

Wrapping Up: Your Path to Successful Kamal Deployments

The “docker: command not found” error is a rite of passage for Kamal usersโ€”frustrating when you first encounter it, but trivial once you understand the solution. The key takeaway is simple: fresh servers need kamal setup, not kamal deploy.

By following this guide, you now have three proven approaches to resolve this error, plus the knowledge to troubleshoot common deployment issues. Whether you choose Kamal’s automated setup, manual Docker installation, or Docker-ready droplets, you’re equipped to deploy your Rails applications confidently.

Remember, Kamal is designed to simplify containerized deployments without vendor lock-in. Once you get past this initial setup hurdle, you’ll experience the joy of zero-downtime deploys, easy rollbacks, and the freedom to run your applications anywhere. For teams managing complex Rails applications or facing unique deployment challenges beyond standard Kamal setups, professional Ruby on Rails consulting can provide customized solutions tailored to your infrastructure needs.

Ready to deploy? Commit your changes, run kamal setup, and watch your Rails application come to life on your DigitalOcean droplet.

Frequently Asked Questions

A: Kamal separates initial server setup (kamal setup) from regular deployments (kamal deploy). This design allows for faster subsequent deployments and gives you explicit control over when server provisioning occurs.

A: Yes, running kamal setup on an already-configured server is safe. Kamal will skip steps that are already complete and only perform necessary updates.

A: For small Rails applications, a 1GB RAM droplet ($6/month on DigitalOcean) is sufficient. Production applications with databases should start at 2GB or 4GB for comfortable performance.

A: Yes, Kamal requires a container registry (like Docker Hub, GitHub Container Registry, or DigitalOcean Container Registry) to push and pull your application images during deployment.

A: Absolutely. While Kamal can deploy database containers as “accessories,” using managed database services like DigitalOcean Managed Databases is recommended for production applications.

Similar Posts