How to rollback a deployment with Kamal?

less than 1 minute read

Kamal provides an easy way to rollback a deployment using the kamal rollback command.

Command:

kamal rollback [VERSION]

To rollback you need to specify the version you want to rollback to.

To find the version you can use the following command to list the available containers.

kamal app containers -q
App Host: 37.27.188.95
CONTAINER ID   IMAGE                                                            COMMAND                  CREATED          STATUS                        PORTS     NAMES
df826bc62d45   deepakmahakale/meetup:9533761e01c8810dc5a678675c0907a91cf7935d   "/rails/bin/docker-e…"   26 seconds ago   Up 25 seconds                 80/tcp    meetup-web-9533761e01c8810dc5a678675c0907a91cf7935d
911a7e9baa16   deepakmahakale/meetup:f34e9efe57fb781c89b3ce3f85427bb230b34d9e   "/rails/bin/docker-e…"   10 days ago      Exited (255) 18 seconds ago             meetup-web-f34e9efe57fb781c89b3ce3f85427bb230b34d9e

Note:
9533761e01c8810dc5a678675c0907a91cf7935d is the version that we just deployed (bad version)
f34e9efe57fb781c89b3ce3f85427bb230b34d9e is the previous stable version that we want to rollback to.

Once we have identified the version we want to rollback to we can run the following command:

kamal rollback f34e9efe57fb781c89b3ce3f85427bb230b34d9e

This will rollback the deployment to the specified version.