✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Always Restart Policy

The Always Restart Policy in Docker ensures containers restart automatically under specific conditions, enhancing system reliability and uptime

The always restart policy unconditionally restarts a container whenever it stops, for any reason — including a deliberate, explicit docker stop — and even restarts it automatically if the Docker daemon itself restarts, making it the most aggressive of the available restart policies.

Configuring always

docker run -d --restart=always --name myapp myapp:1.0

Why always Restarts Even After a Deliberate Stop

Unlike unless-stopped, the always policy does not remember or respect a deliberate stop — if the Docker daemon restarts (a host reboot, a daemon upgrade) while a container that was explicitly stopped is configured with always, that container will be started again automatically.

docker run -d --restart=always --name myapp myapp:1.0
docker stop myapp
sudo systemctl restart docker
docker ps --filter "name=myapp"

Surprisingly, myapp appears running again after the daemon restart, despite having been explicitly stopped beforehand — this is the key distinguishing behavior of always versus unless-stopped.

Why This Behavior Can Be Surprising or Undesirable

An operator who deliberately stopped a container, intending for it to remain stopped, might be surprised to find it running again after an unrelated daemon restart — this is precisely the scenario unless-stopped exists to avoid.

docker run -d --restart=unless-stopped --name myapp myapp:1.0

For most production services, unless-stopped is generally the more predictable and commonly preferred choice for exactly this reason.

When always Might Still Be the Right Choice

For a container that genuinely should never remain stopped under any circumstances — perhaps a critical piece of infrastructure where even a deliberate stop should be quickly reversed by automation — always's unconditional behavior might be intentional and appropriate.

docker update --restart=always myapp

Why Understanding the always Policy Matters

Recognizing the specific, sometimes surprising difference between always and unless-stopped — particularly around how each treats a deliberate stop — is essential for choosing the restart policy that actually matches the intended operational behavior for a given container.