Docker Rolling Updates & Rollbacks, Explained From Zero
How Docker Swarm replaces a live, traffic-serving service with a new version — one small batch at a time — and quietly undoes the change the moment something looks wrong.
Imagine replacing every tire on a moving car. Stopping the car, pulling off all four tires at once, and putting new ones on would obviously be disastrous — the car needs at least some tires touching the road at every single moment to keep moving safely. A skilled pit crew instead replaces tires one at a time, always leaving enough of the car supported to keep going, and if a new tire turns out to be faulty, they can put the old one back before it causes real damage. A rolling update in Docker does exactly this for a running application: replacing old containers with new ones a few at a time, never taking the whole service down at once, and rolling back automatically if the new version turns out to be broken.
1What Are Rolling Updates, and Why Does Docker Need Them?
The problem starts with a very ordinary question: how do you change something people are actively using?
The naive approach, and why it fails
The simplest possible way to deploy a new version of an application is to stop every running copy of the old version and start every copy of the new version. This is easy to reason about, but it comes with an unavoidable cost: for some window of time, however brief, there is no running application at all to serve requests. For anything users actually depend on continuously, that gap is a real, visible outage — even if it only lasts a few seconds.
What a rolling update does instead
A rolling update replaces a running service’s containers gradually, in small batches, rather than all at once. At every point during the process, some containers are still running the old version and actively serving traffic while a small number are being swapped for the new version, so the service as a whole never fully stops. Docker Swarm — Docker’s built-in orchestration mode for running services across a cluster of machines — implements this as a first-class, built-in feature of how it manages services.
Think of a restaurant slowly retraining its kitchen staff on a new menu, one cook at a time, while the rest keep cooking the old menu — rather than sending every cook to training simultaneously and closing the restaurant for the afternoon.
Why rollbacks are the natural companion feature
Deploying gradually creates a valuable side effect: since only a portion of the service changes at first, problems with the new version can often be caught before every container has been replaced. A rollback reverses this process, replacing the new version’s containers back with the previous, known-good version — either triggered manually by an operator, or automatically by Docker itself when it detects the new version isn’t healthy.
The desired state
A Swarm object describing what should be running — which image, how many copies, and how updates should happen.
One running instance
A single container instance of a service, scheduled onto a specific node in the cluster.
Gradual replacement
Swapping a service’s tasks from an old version to a new one in controlled, incremental batches.
Controlled reversal
Reverting a service’s tasks back to a previous known-good version, following the same gradual, controlled approach.
Rolling updates as described here are a Swarm mode feature. Running a single container directly with the basic docker run command has no built-in concept of a gradual, orchestrated rollout — that coordination logic lives specifically in Swarm’s service management layer.
2The Building Blocks: Services, Tasks, and the Update Controller
A handful of Swarm concepts cooperate to make gradual, controlled rollouts possible.
1. The Swarm Manager
The node (or nodes) in the cluster responsible for maintaining the overall desired state of every service, including deciding when and how an update should progress across the cluster.
2. The Service Specification
The stored definition of what a service should look like — which image, how many replicas, and critically, the update configuration describing how future rollouts of this specific service should behave.
3. Tasks and Their States
Each running copy of a service is tracked as an individual task, with its own lifecycle state — pending, starting, running, healthy, failed — that the manager continuously monitors throughout an update.
4. The Update Controller
The internal logic inside the Swarm manager that actually drives an update forward: deciding which batch of tasks to replace next, waiting for the configured delay, checking health, and deciding whether to proceed, pause, or roll back.
Where the update’s behavior is actually configured
Rather than being a single fixed process, every service can define its own update behavior — how many tasks to replace at once, how long to wait between batches, in what order the old task is stopped relative to the new one starting, and what to do if a failure is detected. This configuration lives directly on the service itself, so different services in the same cluster can roll out in completely different ways depending on how sensitive each one is to a brief disruption.
flowchart TB
A["Update Requested
(new image / config)"] --> B["Swarm Manager"]
B --> C["Update Controller"]
C --> D["Read Service's
Update Configuration"]
D --> E["Select Next Batch
of Tasks to Replace"]
E --> F["Stop/Start Tasks
per configured order"]
F --> G{"Health Check
Passed?"}
G -->|"Yes"| H["Wait configured delay,
proceed to next batch"]
G -->|"No"| I["Apply configured
failure action"]
H --> E
A rolling update does not create a second, temporary copy of the entire service running side by side with the old one at full scale. It replaces the existing tasks in place, batch by batch, so the total number of running replicas generally stays close to the configured count throughout the process.
3How a Rolling Update Actually Progresses
Underneath the concept, it’s a repeating loop over small batches of tasks.
When an update is requested, the Swarm manager doesn’t touch every task at once. It divides the full set of tasks into batches, sized according to the service’s configured parallelism, and processes one batch fully before ever starting the next. This batch-by-batch looping is the actual mechanism that turns “replace everything” into “replace gradually.”
Select a Batch
The controller picks the next group of tasks to update, sized according to the configured parallelism — often just one or two at a time for sensitive services.
Apply the Configured Order
Depending on configuration, the old task in this batch is either stopped before the new one starts, or the new one is started first and only then is the old one stopped — a meaningful choice discussed further in the next chapter.
Wait for Readiness
The controller waits for the new task to reach a running, and ideally healthy, state before considering this batch complete.
Pause for the Configured Delay
Before moving to the next batch, the controller waits for a configured delay period — giving the newly updated tasks time to prove themselves stable under real traffic before more of the service is touched.
Repeat Until Complete
This cycle repeats, batch after batch, until every task has been replaced, at which point the service is reported as having fully converged to the new desired state.
4The Levers: Parallelism, Delay, and Start Order
Three configuration choices control almost everything about how disruptive an update feels.
How many at once
The number of tasks updated simultaneously in each batch — a small number is cautious and slow; a large number is fast but riskier.
Time between batches
How long the controller pauses after a batch finishes before starting the next one, giving time to observe real behavior under traffic.
Stop-first or start-first
Whether the old task is stopped before the new one starts, or the new one starts and proves itself before the old one is removed.
What to do if a batch fails
Whether the controller should pause the update, continue anyway, or trigger an automatic rollback when a batch doesn’t succeed.
Stop-first vs start-first, in practice
With a stop-first order, the old task is removed before its replacement starts — this briefly reduces total capacity for that batch, but guarantees the old and new versions are never running side by side on the same batch slot. With a start-first order, the new task is started and given a chance to become healthy before the old task is stopped — preserving full capacity throughout, at the cost of a short window where both versions are simultaneously live and potentially receiving traffic.
Stop-First Order
- Never runs old and new versions simultaneously in the same slot
- Simpler behavior to reason about for stateful or version-sensitive services
- Momentarily reduces available capacity during each batch
Start-First Order
- Preserves full service capacity throughout the update
- Briefly runs both versions at once, which must be safe for the application
- Generally preferred for services where capacity dips are unacceptable
A very low parallelism value combined with a meaningful delay is the classic “cautious” configuration for critical, user-facing services — it trades a longer total rollout time for far greater confidence that a problem gets caught while only a small fraction of the service is affected.
5Health Checks: How Docker Knows an Update Actually Worked
Without a way to detect failure, none of the automated safety behavior would be possible.
“Running” is not the same as “working”
A container can be fully running — its process started successfully, no crash occurred — while the application inside it is completely unable to serve real requests, for example because it can’t reach a required database. Swarm’s rollout logic needs a more meaningful signal than “the process started” to safely decide whether a batch actually succeeded, which is exactly what a configured health check provides.
How health checks influence the rollout
When a service defines a health check, Swarm waits for newly started tasks to report as healthy — not merely running — before considering that batch of the update complete and moving on to the next one. If a task fails its health check within the configured grace period, the controller treats that as a failed update for this batch and applies whatever failure action the service is configured to take.
Grace period
A configurable window during which a newly started task is given time to become healthy before its status is actually judged, avoiding false failures during a normal application startup sequence.
Retries and intervals
Health checks typically run repeatedly at a configured interval, with a configured number of allowed consecutive failures before a task is finally marked unhealthy, smoothing over brief, harmless blips.
Feeding the failure action
An unhealthy task during an update is the primary trigger for the failure action described in the next chapter — without health checks configured, Swarm has far less insight into whether a rollout is actually going well.
Rolling out an update to a service with no health check configured at all. Without one, Swarm can only judge success by whether the container process is running, which misses an enormous range of real-world failures where a container starts but the application inside never actually becomes usable.
6Rollbacks: Automatic and Manual
Reverting a bad update follows the same gradual philosophy as rolling it out.
Manual rollback
An operator who notices a problem — even one health checks didn’t catch, such as a subtle business-logic bug — can explicitly instruct Swarm to roll a service back to its previous specification. Swarm treats this the same way it treats a forward update: as a gradual, batch-by-batch replacement, just moving in the opposite direction, back to the prior known-good version.
Automatic rollback
A service can also be configured so that Swarm rolls back on its own, without any human intervention, the moment its configured failure action determines that an update batch has failed — typically due to health check failures beyond an allowed threshold. This turns a bad deployment into a self-correcting event rather than an incident that requires someone to notice and react.
sequenceDiagram
participant Op as Operator
participant Mgr as Swarm Manager
participant New as New Version Tasks
participant Old as Previous Version
Op->>Mgr: Request update to new image
Mgr->>New: Roll out batch 1
New-->>Mgr: Health check failing
Mgr->>Mgr: Evaluate configured failure action
alt Automatic rollback configured
Mgr->>Old: Revert affected tasks to previous spec
Old-->>Mgr: Healthy
Mgr-->>Op: Update rolled back automatically
else Manual rollback required
Mgr-->>Op: Update paused, awaiting operator decision
Op->>Mgr: Trigger rollback
Mgr->>Old: Revert to previous spec
end
A rollback reverts to the service’s previously recorded specification, not necessarily to an arbitrary earlier version — which is why keeping deployments incremental, one meaningful change at a time, keeps rollbacks predictable and easy to reason about.
7Advantages, Disadvantages, and Trade-offs
Gradual, automated rollouts remove a lot of manual risk — but they add their own complexity.
Advantages
- Avoids full-service outages during routine deployments
- Limits the blast radius of a bad release to a small batch before it’s caught
- Automatic rollback removes reliance on a human noticing a problem quickly
- Fully configurable per service, letting critical and non-critical services roll out differently
- Built directly into Swarm, requiring no separate deployment tooling for the basic case
Disadvantages / Trade-offs
- Two versions of an application briefly run side by side with start-first ordering, which the application must tolerate safely
- A cautious configuration with low parallelism can make large-scale rollouts take a long time
- Effectiveness depends heavily on a genuinely meaningful, well-tuned health check
- Database schema and data-format changes need separate, careful compatibility planning beyond what rolling updates alone provide
- A rollback reverts application code, not necessarily any external state changes the new version already made
8Security Considerations
Deployment mechanics and security posture intersect more than they might first appear to.
Who is allowed to trigger an update
The ability to update a running service is effectively the ability to change what code is running in production — a highly privileged action. Controlling exactly who and what (which pipeline identities, which individuals) can request a service update deserves the same scrutiny as any other high-impact production access.
Rollbacks and previously patched vulnerabilities
An automatic or manual rollback reverts to a prior image, which may itself have contained a security vulnerability that the very update being rolled back was meant to fix. Teams relying on rollback as a safety net need a process for quickly re-addressing any security-relevant fix that a rollback has temporarily undone, rather than assuming the rollback is a fully safe, permanent resting state.
Restrict who can deploy
Limit which identities are permitted to trigger updates and rollbacks on sensitive services, and audit those actions.
Verify what’s being deployed
Pair rolling updates with image signing and verification so a rollout can only ever deploy a genuinely trusted image.
Track what a rollback reverts
Treat a rollback that undoes a security fix as an open issue requiring prompt follow-up, not as a resolved situation.
Don’t let checks be gamed
A health check endpoint that’s trivially easy to make “pass” regardless of real application state undermines the entire safety mechanism updates rely on.
Treating “the rollback worked” as the end of the incident, without separately tracking and re-applying whatever security-relevant change the rolled-back update was actually trying to deliver.
9Monitoring, Logging, and Metrics
Watching an update in progress is what actually makes the automated safety net trustworthy.
Tracking convergence
Swarm continuously tracks how close a service is to its fully updated desired state, making it possible to observe an update’s real-time progress — how many tasks have been updated, how many remain, and whether any are currently failing — rather than only finding out the final outcome after the fact.
Update state and task events
Swarm exposes the current update state of a service (in progress, paused, completed, rolled back) along with individual task-level events, giving visibility into exactly where in the batch sequence an update currently stands.
Application and health-check metrics
Beyond Swarm’s own state, monitoring the application’s own error rates, latency, and health-check results during a rollout is what actually reveals whether the new version is behaving well under real traffic, not just whether it started successfully.
Rollback frequency as a signal
Tracking how often updates end in a rollback, over time, is a valuable higher-level metric — a rising rollback rate often points to gaps earlier in the pipeline, such as insufficient pre-production testing, rather than a problem with the rollout mechanism itself.
10Design Patterns and Anti-Patterns
The gap between a smooth rollout culture and a nerve-wracking one is mostly about deliberate configuration.
Pattern: cautious parallelism for critical services
Configuring a low parallelism value and a meaningful delay for user-facing, critical services trades rollout speed for the ability to catch a bad release while only a small fraction of the service has been touched — a trade most teams gladly accept for anything customers directly depend on.
Pattern: meaningful, application-aware health checks
Building a health check that genuinely reflects whether the application can do its job — checking real dependencies like database connectivity, not just returning a static success response — gives the update controller an honest signal to act on, rather than a check that technically passes while the application is actually broken.
Problem
Deploying updates with maximum parallelism and no health check configured, so every task is replaced at once with no meaningful safety net.
Why It’s Harmful
A bad release affects the entire service simultaneously, with nothing to detect the problem automatically or limit its impact to a small batch first.
Correct Approach
Configure a genuine health check and a parallelism value appropriate to how much disruption the service can tolerate, rather than defaulting to the fastest possible rollout.
Problem
Relying entirely on rolling updates and rollbacks to manage a change that also involves an incompatible database schema migration.
Why It’s Harmful
While old and new application versions briefly run side by side during the rollout, an incompatible schema change can break one or both versions in ways rolling updates alone have no way to detect or safely reverse.
Correct Approach
Design schema changes to be backward-compatible across the rollout window, and treat data migrations as a separate, carefully sequenced concern from the application rollout itself.
11Best Practices and Common Mistakes
A short list of habits that make rolling updates something teams trust rather than fear.
Configure automatic rollback
Enable automatic rollback on failure for critical services, rather than depending entirely on a human noticing a problem in time.
Match parallelism to blast-radius tolerance
Choose a parallelism and delay combination that reflects how much impact the service can safely absorb if a batch goes wrong.
Test the rollback path, not just the forward update
Periodically verify that rolling back actually restores a healthy previous state, rather than assuming it works because it’s never been needed yet.
Keep changes small and incremental
Smaller, more frequent updates make both the update itself and any needed rollback far easier to reason about than large, infrequent ones.
Deploying without a health check
Leaving Swarm to judge success purely by whether a process started, missing the vast majority of real-world application-level failures.
Ignoring the start-first vs stop-first trade-off
Using start-first ordering for an application that isn’t actually safe to run in two versions simultaneously, or stop-first for one that can’t tolerate any capacity dip.
12Real-World and Industry Examples
Rolling updates are one of the most consistently relied-upon patterns across modern container orchestration.
Everyday web and API services
Teams running customer-facing web applications and APIs on Swarm routinely use rolling updates as their standard deployment method, specifically to avoid the visible downtime a stop-everything deployment would cause.
Continuous delivery pipelines
Automated deployment pipelines commonly trigger a rolling update as the final step after tests pass, relying on the built-in health-check-driven safety net as an additional layer of protection beyond pre-deployment testing alone.
High-availability infrastructure services
Internal infrastructure components that many other services depend on — reverse proxies, internal APIs, caching layers — are especially likely to use cautious, low-parallelism rolling updates, since an outage here would ripple outward to everything depending on them.
Kubernetes’ parallel concept
Kubernetes, the other major container orchestration platform, implements a closely related rolling update strategy of its own for its Deployment objects, reflecting how broadly this gradual-replacement pattern has become an industry-standard approach to zero-downtime deployment, independent of which specific orchestrator a team uses.
13Frequently Asked Questions
The rolling update mechanism described here is a feature of Docker’s Swarm orchestration mode. Running individual containers directly, outside of Swarm, has no equivalent built-in gradual rollout behavior.
With appropriate parallelism, delay, and start-first ordering, the goal is that users experience no visible disruption at all, since the service as a whole continues serving requests throughout the entire process.
No. A rollback reverts which application code is running, not any external data changes that code already made while it was live. Data-level changes need to be handled with their own, separate compatibility and recovery planning.
It’s driven by the service’s configured failure action combined with health check results — when enough tasks in an update fail their health checks within the configured tolerance, Swarm applies whatever failure action the service was configured with, which can include an automatic rollback.
A standard rollback reverts to the immediately previous service specification. Reaching further back typically means explicitly redeploying that earlier version’s specification directly, rather than repeatedly issuing rollback commands.
Technically no — updates will still proceed using process state alone if no health check is configured. But without one, Swarm loses most of its ability to actually detect a bad release, which defeats much of the safety value rolling updates are meant to provide.
14Summary and Key Takeaways
Rolling updates turn deploying a new version of a service from a risky, all-at-once event into a controlled, incremental process — replacing a small batch of tasks, pausing to verify health, and repeating until the whole service has moved to the new version, all while continuing to serve traffic throughout. Rollbacks are the natural safety net that makes this gradual approach trustworthy: whether triggered manually by an operator or automatically by a failed health check, they let a bad release be undone with the same careful, batch-by-batch discipline used to roll it out in the first place. Understanding the specific levers — parallelism, delay, start order, and the failure action — is what turns this from an abstract safety feature into a deployment strategy actually tuned to what each individual service can and can’t tolerate.
Key Takeaways
- Rolling updates replace tasks in small batches, never taking the whole service offline at once.
- Parallelism, delay, and start order are the main configurable levers that determine how cautious or fast a rollout is.
- Health checks are what make the whole safety mechanism meaningful — without one, Swarm can only judge success by whether a process started.
- Rollbacks can be manual or automatic, with automatic rollback removing dependence on a human catching the problem in time.
- A rollback reverts application code, not external state — database and data changes need their own separate compatibility planning.
- Access to trigger deployments and rollbacks is a privileged action and deserves the same scrutiny as any other production access control.
- The pattern generalizes well beyond Docker — Kubernetes and other orchestrators implement closely related rolling deployment strategies of their own.