13.2.3.3 Compose Rollback
A focused guide to Compose Rollback, connecting core concepts with practical Docker and container operations.
Compose rollback reverts a Compose-based deployment to a previous image version by updating the Compose file's image reference and reapplying it, a straightforward process given Compose's declarative nature, though it lacks the automatic, gradual rollout (and rollback) behavior a true orchestrator provides.
Performing a Basic Compose Rollback
Reverting requires changing the image tag back to a previous, known-good version and reapplying the Compose configuration.
services:
app:
image: registry.example.com/myapp:v1.4.2
docker compose up -d
Compose recreates the app service using this reverted image reference, replacing the currently running, problematic version.
Why Compose Rollback Happens All at Once, Not Gradually
Unlike Swarm or Kubernetes, which can perform a gradual, rolling rollback across multiple replicas, a standard Compose deployment typically replaces a service's container directly, without that same gradual replacement behavior.
docker compose up -d --no-deps app
This recreates just the specified service, though still as a direct replacement rather than a gradual rollout.
Why Brief Downtime Is a Reasonable Expectation With This Approach
Given this direct replacement behavior, a Compose-based rollback (or any update) typically involves brief downtime for that service, an acceptable trade-off for many applications not requiring zero-downtime updates.
docker compose up -d
docker compose ps
Scripting a Rollback for Faster, More Reliable Execution
A dedicated rollback script, rather than manual file editing, reduces the chance of error during what's often a time-pressured situation.
#!/bin/bash
sed -i "s|image: registry.example.com/myapp:.*|image: registry.example.com/myapp:$1|" docker-compose.yml
docker compose up -d
Why Compose Rollback Matters
Understanding Compose's direct-replacement rollback behavior, including its lack of gradual rollout and the resulting brief downtime, helps set appropriate expectations for applications using this delivery target, while still providing a straightforward, reliable way to revert when necessary.