Docker Swarm
Estimated reading: 3 minutes 3 views

πŸ”„ How to Perform Rolling Updates in Docker Swarm

Performing rolling updates in a Docker Swarm environment allows you to update services incrementally without downtime, ensuring continuous availability. Here’s a visually structured guide to doing it right, step-by-step πŸš€


βš™οΈ Initialize Docker Swarm (if not already done)

Make sure your Swarm cluster is ready by initializing it:

docker swarm init

βœ… This command makes your current node the Swarm manager.


πŸ“¦ Deploy an Initial Service

Let’s deploy an Nginx service with 3 replicas:

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

πŸ” Verify the service is running:

docker service ls

πŸ”§ Configure Rolling Update Parameters

You can fine-tune how the rolling updates behave using these flags:

🏷️ FlagπŸ” DescriptionπŸ’‘ Example
--update-parallelismNumber of containers updated at the same time--update-parallelism 1
--update-delayWait time between updates--update-delay 10s
--update-failure-actionWhat to do if an update fails (pause or continue)--update-failure-action pause

πŸ“Œ Example:

docker service create \
--name my_service \
--replicas 3 \
--update-parallelism 1 \
--update-delay 10s \
nginx:1.19

πŸ” Perform the Rolling Update

Let’s update the service to a newer version:

docker service update --image nginx:1.21 my_service

🧠 Docker Swarm will now update your containers one at a time based on your config.


πŸ“Š Monitor the Update Progress

Keep track of what’s happening:

docker service ps my_service

πŸ‘€ You’ll see a mix of old and new versions running during the transition.


↩️ Rollback if Something Goes Wrong

Need to undo the update? No worries:

docker service rollback my_service

πŸ”„ This command restores the previous configuration and image version.


βœ… Best Practices for Rolling Updates

πŸ’‘ Keep your updates safe and reliable with these practices:

  • πŸ”‚ Use small batches – Set --update-parallelism to a low number.
  • ⏱️ Introduce delays – Let your system stabilize between updates.
  • ❀️ Enable health checks – Let Docker detect and manage unhealthy containers.
  • πŸ“ˆ Monitor everything – Use tools like Prometheus and Grafana.
  • πŸ§ͺ Test in staging first – Never deploy blind into production.
  • 🐦 Try canary deployments – Gradual rollout to avoid system-wide issues.

πŸ“ Summary Table: Key Docker Service Update Flags

πŸ”§ FlagπŸ“˜ DescriptionπŸ§ͺ Example
--update-parallelismTasks updated simultaneously--update-parallelism 1
--update-delayDelay between update batches--update-delay 10s
--update-failure-actionPause or continue on failure--update-failure-action pause
--rollbackRestore previous versiondocker service rollback my_service

❓ FAQ: Rolling Updates in Docker Swarm

Q1: What happens during a rolling update?
πŸ” Docker updates a few containers at a time, keeping the service running without interruption.

Q2: How can I control how many containers update at once?
βš™οΈ Use --update-parallelism to define the update batch size.

Q3: Can I pause or stop an update if something goes wrong?
πŸ›‘ Yes, use --update-failure-action pause to automatically halt updates on failure.

Q4: How do I check the status of a rolling update?
πŸ“‹ Use docker service ps my_service to monitor task status and progress.

Q5: Is rollback automatic?
πŸ”™ Rollback is manual by default but can be automated using update failure policies.


πŸš€ Call to Action

πŸš€ Call to Action

πŸ§ͺ Try it yourself!
Start with a sample Nginx service and practice updating it:

πŸ”§ Deploy:

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

πŸ”„ Update it:

docker service update --image nginx:1.21 test_service

πŸ” Monitor:

docker service ps test_service

↩️ Roll back (if needed):

docker service rollback test_service

🎯 Integrate rolling updates into your CI/CD workflow for smooth, automated deployments with zero downtime.


πŸ”– Metadata for SEO

SEO Title:
How to Perform Rolling Updates in Docker Swarm: Step-by-Step Guide

Meta Title:
Docker Swarm Rolling Updates Tutorial | Zero Downtime Deployments

Meta Description:
Learn how to perform rolling updates in Docker Swarm to update your services without downtime. Step-by-step instructions, best practices, and rollback tips included.

URL Slug:
docker-swarm-rolling-updates-guide

Meta Keywords:
Docker Swarm rolling updates, Docker Swarm service update, zero downtime deployment, Docker rolling update best practices, Docker service rollback


Leave a Reply

Your email address will not be published. Required fields are marked *

Share this Doc

How to Perform Rolling Updates in Docker Swarm

Or copy link

CONTENTS
Scroll to Top