6.3.3.4 Unless Stopped Policy
A focused guide to Unless Stopped Policy, connecting core concepts with practical Docker and container operations.
The unless-stopped restart policy automatically restarts a container after a crash or daemon restart, but specifically respects a deliberate, explicit stop — once an operator stops the container intentionally, it stays stopped even through a subsequent daemon restart, making this generally the most predictable choice for production services.
Configuring unless-stopped
docker run -d --restart=unless-stopped --name myapp myapp:1.0
Why This Policy Respects a Deliberate Stop
Unlike always, unless-stopped tracks whether a container was explicitly stopped by an operator, honoring that intent even across a subsequent daemon restart.
docker run -d --restart=unless-stopped --name myapp myapp:1.0
docker stop myapp
sudo systemctl restart docker
docker ps --filter "name=myapp"
myapp remains stopped after the daemon restart, correctly respecting the earlier deliberate stop — this is the key behavior distinguishing it from always.
Why unless-stopped Still Provides Crash Recovery
Despite respecting a deliberate stop, this policy still provides automatic recovery from an unexpected crash, restarting the container in exactly the cases where automatic recovery is actually wanted.
docker run -d --restart=unless-stopped --name myapp myapp:1.0
docker kill myapp
docker ps --filter "name=myapp"
If myapp crashes (simulated here with kill, distinct from a deliberate stop), it is automatically restarted, since this wasn't an intentional, explicit stop.
Why unless-stopped Is Often the Recommended Default
This policy combines the resilience benefit of automatic crash recovery with the predictability of respecting deliberate operator actions, making it a sensible default choice for most production service containers.
docker update --restart=unless-stopped myapp
Why the unless-stopped Policy Matters
For the common case of a production service that should recover automatically from crashes but should also stay stopped when an operator deliberately stops it, unless-stopped provides exactly the behavior most operators actually expect, avoiding the surprising restart-after-deliberate-stop behavior that always can produce.