Kamal’s new server exec command
Kamal v1.6.0 just came out and it comes with a new server exec command. Kamal already had app exec
and accessory exec
which would let you run a command within the container, server exec
adds the ability to run a command directly on the host server that your containers are running on.
app exec
is great for digging around your container or debugging why your container might not be booting up but server exec
helps with everything at the host server level. For the most part with Kamal once you boot up your server there’s really not much else, everything just runs in a container on the server via Docker.
But maybe you want to check that NTP is in sync across your servers:
$ kamal server exec "date"
Running 'date' on 867.53.0.9, 867.53.0.10...
Running the pre-connect hook...
INFO [d86b39b2] Running /usr/bin/env .kamal/hooks/pre-connect as n@localhost
INFO [d86b39b2] Finished in 0.544 seconds with exit status 0 (successful).
INFO [5f6830ef] Running /usr/bin/env date on 867.53.0.9
INFO [5f6830ef] Finished in 0.151 seconds with exit status 0 (successful).
App Host: 867.53.0.9
Wed Jun 5 21:49:52 UTC 2024
INFO [61992128] Running /usr/bin/env date on 867.53.0.9
INFO [dddd5b96] Running /usr/bin/env date on 867.53.0.10
INFO [dddd5b96] Finished in 0.171 seconds with exit status 0 (successful).
App Host: 867.53.0.10
Wed Jun 5 21:49:52 UTC 2024
Or maybe you need to confirm the version of Docker that’s running on your servers to see if it’s time to upgrade:
$ kamal server exec "docker -v"
Running 'docker -v' on 867.53.0.9, 867.53.0.10...
Running the pre-connect hook...
INFO [4fb94123] Running /usr/bin/env .kamal/hooks/pre-connect as n@localhost
INFO [4fb94123] Finished in 0.424 seconds with exit status 0 (successful).
INFO [3570547f] Running docker -v on 867.53.0.9
INFO [03c1ca95] Running docker -v on 867.53.0.10
INFO [3570547f] Finished in 0.169 seconds with exit status 0 (successful).
App Host: 867.53.0.9
Docker version 25.0.3, build 4debf41
INFO [03c1ca95] Finished in 0.168 seconds with exit status 0 (successful).
App Host: 867.53.0.10
Docker version 25.0.3, build 4debf41
Or maybe you just want a simple way to SSH into a specific role to verify something on the server with an interactive session:
kamal server exec -i -r worker "/bin/bash"
Running '/bin/bash' on 867.53.0.9 interactively...
ubuntu@heyo:~#
The new server exec
command offers a simple option for some additional server maintenance and provisioning if you need it without having to reach for something more complex. We can leave the majority of the provisioning to Docker when we build our containers and then sprinkle in some post-deployment management via Kamal.