The 3 Kamal Execs
There are 3 kinds of kamal exec commands. Shit’s always confusing. So I wrote this to unconfuse me.
Interactive bash session:
You have to run these locally, from the project’s root folder.
To start one in the host server:
kamal server exec -i "/bin/bash"
(You can also just ssh into the server for this usecase. But with the kamal way, you can run them on specific hosts (–primary).)
To start one in the main web app’s container:
kamal app exec --interactive --reuse "bin/rails console"
kamal app exec -i --reuse "/bin/bash"
kamal app exec -i --reuse "bash"
kamal app exec -i --reuse "bin/rails dbconsole --include-password" # will start psql if the rails app used pg
To start one in the accessory service’s container:
kamal accessory exec -i --reuse "/bin/bash"
One-off commands
Instead of an interactive bash session, you can just execute the desired command in one go.
Just drop the -i (--interactive) flag. And mention the command in place of /bin/bash.
If the command doesn’t recognize “/bin/bash”, try just “sh”. It might work.
Doing the same from within the host machine
The above are just wrappers around docker exec.
So you can just ssh into the host machine and do the following instead of the above ones.
These would also feel much faster than the above.
Run docker ps to get the IDs of the running containers.
Use them to start an interactive session using docker exec like so:
docker exec -it <container-id> "/bin/bash"