Kamal, a Ruby Deployment Tool, is Very Convenient

I didn’t know about this in recent years, but I found out that current Rails includes Kamal, a very convenient deployment tool.

GitHub: basecamp/kamal
Official Site

Kamal was originally created as a deployment tool for Ruby on Rails, but now it can be used for any project that deploys as a Docker container.

What Kamal Does

  1. When you run kamal deploy on any project,
  2. It generates a Docker image
  3. Registers the generated Docker image in a registry like DockerHub
  4. Downloads and starts the Docker image on the target Ubuntu server
  5. Replaces the already running Docker container on the Ubuntu server without stopping it
    • Performs health checks before replacement (default accesses /up), and proceeds with the replacement if it’s deemed healthy
  6. Issues and renews SSL/TLS certificates

That’s roughly how it works.

What Kamal Does Not Do

It doesn’t handle things like automatic restarts when stopped, which Kubernetes or Fargate would handle.
Kamal is just a deployment tool, not an operational platform.

Projects Suitable for Kamal

Kamal is not an orchestration tool, but rather a tool for generating Docker images and deploying them to target servers.
Therefore, it probably isn’t suitable for deploying systems that require orchestration at a scale of hundreds of servers.
However, for internal servers, personal web applications, or small-scale systems with a few servers, it’s fully functional and more suitable due to its simplicity.

By the way, this site is also deployed using Kamal.

How to Use Kamal

If you’re using the latest Ruby On Rails 8.1 series, Kamal is included by default.

Prerequisites

  1. Ensure you can SSH into the target Ubuntu server.
  2. Log in to a registry like DockerHub and create a repository (private is okay)
  3. Register a domain name in DNS (register a record linking the server’s global IP address and the name)
  4. Configure various settings in config/deploy.yml

Preparing for Deployment

Run the following only once initially

$ ./bin/kamal setup

Deployment

After setup is complete

./bin/kamal deploy

This completes the deployment to the target server.
There’s an issue about whether to use the root user or a regular user for deployment on Ubuntu, but initially, it’s probably okay to use root.
After deployment, try accessing it with the name registered in DNS.
If the SSL/TLS certificate registration completes normally, you should be able to access it via https://~.

It’s very helpful to have such a convenient and robust deployment tool built in.
In the future, I plan to use it for both private and work Ruby On Rails projects.

© 2025 Hiroe Tech Notes. All rights reserved.

Comments

No comments yet.