Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 228 of 8023. Docker Orchestration and StorageFree lesson

Updating Swarm Services with Rolling Deployments

Learners will execute zero-downtime application updates by configuring rolling update strategies and monitoring deployment health during the transition process.

In this lesson, you will learn how to update your application across a cluster without causing downtime by using Docker Swarm’s rolling update strategy.

Understanding Rolling Deployments

When you need to update your application—perhaps to deploy a new feature or patch a bug—you don’t want to kill all your containers at once, as this would result in a service outage. A rolling deployment allows you to update your service replicas incrementally. Swarm replaces a specific number of old containers with new ones, waiting for each batch to be healthy before proceeding to the next.

Configuring the Update Strategy

You define this behavior within your service deployment command (or inside your Stack YAML file). The key flags are --update-parallelism (how many replicas to update at once) and --update-delay (the time to wait between batches).

Consider this example where we update a service to a new image version:

docker service update \
  --image my-app:v2 \
  --update-parallelism 2 \
  --update-delay 10s \
  my-web-service

In this scenario, Swarm will shut down two instances of my-web-service, replace them with the v2 image, and then wait 10 seconds before moving on to the next pair.

Monitoring Health During Transitions

If you have configured health checks (which we covered in Lesson 7), Swarm will monitor the containers during the update. If a new container fails its health check, Swarm will pause the update automatically, preventing the faulty code from rolling out to the entire cluster. You can also define an --update-failure-action to instruct Swarm to either pause or rollback the deployment to the previous stable state if things go wrong.

By decoupling the deployment process from manual intervention, you ensure that your production environment remains responsive even while code is being swapped out. This orchestration provides a safety net, ensuring that your users only interact with versions of your app that pass their health checks.

Key Takeaway: Rolling deployments minimize risk and maximize availability by updating your service replicas in controlled, healthy batches rather than all at once.