In this guide, you’ll learn how to scale your services, perform seamless rolling updates, and execute rollbacks in Docker Swarm. We’ll run all commands on the manager node while Swarm orchestrates tasks on worker nodes.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Table of Contents
- Deploying a Service
- Scaling Service Replicas
- Rolling Updates
- Inspecting Update & Rollback Configuration
- Handling Update Failures
- Rolling Back a Service
- References
Deploying a Service
By default, creating a service launches a single replica. Here’s how to deploy a simple web service listening on port 80:Ensure the
web:latest image is available locally or on your registry before creating the service.Scaling Service Replicas
Adjust the replica count of an existing service withdocker service update --replicas.
Scale up to three replicas:
Rolling Updates
Rolling updates replace containers one batch at a time, ensuring zero downtime.Default Update Behavior
After tagging your new image (e.g.,web:2.0), trigger the rolling update:
- Stop one container
- Deploy a new one
- Wait for it to pass health checks
- Repeat until all replicas are updated
Introducing an Update Delay
Pause between updating each batch with--update-delay:
Parallel Updates
Increase throughput by updating multiple tasks simultaneously using--update-parallelism:
Inspecting Update & Rollback Configuration
Usedocker service inspect to review how your service handles updates and rollbacks:
| Configuration | Description |
|---|---|
| Parallelism | Number of tasks updated simultaneously |
| Delay | Time to wait between update batches |
| Failure Action | Behavior when an update fails (pause, continue, rollback) |
| Monitoring Period | Duration Swarm waits for a task to become healthy |
Handling Update Failures
By default, Swarm pauses on the first failure. Change this with--update-failure-action:
| Failure Action | Description |
|---|---|
| pause | Halt the update on error (default) |
| continue | Ignore failures and proceed to next batch |
| rollback | Revert immediately to the previous image/version |
Using
continue can leave your cluster in a mixed-version state. Test thoroughly before choosing this option in production.