Docker Swarm Deployments: Rolling Updates and Rollbacks

Last Updated : 23 Jul, 2025

Docker Swarm is one of the container orchestration tools used to cluster and schedule Docker containers. Developers and IT managers can establish and manage a cluster of Docker nodes as a single virtual system using Swarm. Developers may create a cluster by joining many virtual or real computers together using Docker Swarm. Nodes or daemons are the names given to these lone computers.

What are Rolling Updates?

Rolling updates can update the containers of a service incrementally, swapping out the old version with the new one without bringing down the service. That assures that the application will remain always available, even when updates are underway. Docker Swarm thus automates that process by smoothly removing old containers and replacing them with new ones based on changes made in the developer's configuration.

What are Rollbacks?

Rollbacks are a particular service to a prior version from the swarm. Use the docker service rollback command to return to a service's earlier version. This command returns the service to the settings that existed before the most recent docker service update command. Manual rollback includes halting the changed service and restarting the previous version with Docker commands.

Implementation of Docker Swarm Deployments: Rolling Updates and Rollbacks

Below is the step-by-step implementation of docker swarm deployments: Rolling Updates and Rollbacks:

Step 1: Initialize Docker Swarm

First, if you haven't already initialized your Docker Swarm, you may do so by running the following command.

docker swarm init

Output:

docker_swarm1

Step 2: Deploy a Service

Provide the swarm with a service that you will upgrade later.

docker service create --name my_service --replicas 3 nginx:1.19

Output:

docker_swarm2

Step 3: Verify the Service

Then you can verify the current state of your service.

docker service ls

Output:

docker_swarm3

Step 4: Perform a Rolling Update

You may use the docker service update command to upgrade the service to a new version.

docker service update --image nginx:1.21 my_service

Output:

docker_swarm4

Step 5: Check the Rolling Update

Then you can track the rolling update's development.

docker service ps my_service

Output:

docker_swarm5

Step 6: Rollback the Update

You can roll back to the earlier version if the upgrade doesn't work as intended.

docker service rollback my_service

Output:

docker_swarm6

Step 7: Verify the Rollback

Finally, Verify whether your service has been rolled back by checking its status.

docker service ps my_service

Output:

docker_swarm7

Best Practices of Docker Swarm Deployments: Rolling Updates and Rollbacks

  • Control Update Parameters: Control the number of jobs that are updated at once. To lessen the chance of a service interruption, start with a low number.
  • Leverage Health Checks: To evaluate each container's health automatically, use Docker health checks. With this data, Swarm can determine whether to push updates forward or initiate a rollback.
  • Gradual Rollouts: Update jobs progressively, in batches rather than all at once. This reduces the blast radius in the event of an issue.
  • Monitor Updates in Real-Time: Monitor metrics and logs to identify problems as soon as they appear. Real-time insights can be obtained with tools like Grafana and Promet.

Conclusion

In this article we have learned about docker swarm deployments: Rolling Updates and Rollbacks. Rolling updates and rollbacks in Docker Swarm ensures high availability and fast recovery from unsuccessful deployments. Configuring your services with thoughtful update strategies will ensure smooth transitions between application versions.

Comment