Useful Kamal Command Lines for Rails Deployment
Kamal is the new hotness for Rails deployment and I will say the following:
- Yes it works
- I have rarely had a more frustrating professional censored experience in my life
Useful Command Lines
Launch a bash shell under your app code so you can run a Rake task:
kamal app exec bash -i
Deploy your code UNLESS you have wrapped a shell script around it:
kamal deploy
Deploy my Rails application where I have a shell script wrapped around it:
./deploy
My ./deploy routine looks like this:
cat ./deploy
#!/bin/bash
source .env.production
kamal deploy
unset DATABASE_URL%
NOTE: If you don’t unset DATABASE_URL then your local Rails dev environment will be completely broken because Rails itself is hardwired to use DATABASE_URL over the local database.yml.
Launch a Rails shell in your code base:
kamal app exec bin/rails c -i
Run the database setup:
kamal app exec rails db:setup
Get help
kamal app --help
An interesting edge case using Kamal for deploy happened just today. The situation was this:
Do we have been deploying regularly and last night this happened:
./deploy
Log into image registry...
INFO [bd94f1bc] Running docker --version && docker buildx version as sjohnson@localhost
INFO [bd94f1bc] Finished in 0.362 seconds with exit status 0 (successful).
INFO [dd4c864a] Running docker login -u [REDACTED] -p [REDACTED] as sjohnson@localhost
INFO [dd4c864a] Finished in 1.230 seconds with exit status 0 (successful).
INFO [c176535f] Running docker login -u [REDACTED] -p [REDACTED] on polly.indiana50501.org
Finished all in 1.7 seconds
ERROR (Socket::ResolutionError): Exception while executing on host polly.indiana50501.org: getaddrinfo: nodename nor servname provided, or not known
Trying multiple times to do ./deploy would not fix the problem. The ultimate solution was to do this:
kamal build deliver
Note: To make kamal build deliver work, I had to manually execute one of the commands in my ./deploy routine to make sure the environment variables were setup correctly so my actual step was this:
source .env.production
kamal build deliver
Pizza courtesy of Pizza for Ukraine!
Donate Now to Pizza for Ukraine
Last Updated On: 2025-09-01 04:31:51 -0400