Docker restart policies Explained

What Docker restart policies does, with an example.

Published November 10, 2026

Restart policies tell Docker when to restart a container automatically: no, on-failure, always or unless-stopped. They keep services running after crashes or reboots.

How it works

unless-stopped is the usual choice for services: it restarts after crashes and reboots but not if you stopped it manually. on-failure[:max] restarts only on non-zero exit.

A crash loop will keep restarting, so monitor logs.

Try it

docker run -d --restart unless-stopped nginx
docker inspect -f '{{.HostConfig.RestartPolicy.Name}}' web
unless-stopped

Practical examples

Set at run

docker run -d --restart unless-stopped --name web nginx

On failure with a limit

docker run -d --restart on-failure:5 myapp

Update a running container

docker update --restart unless-stopped web

Compose

services:
  web:
    restart: unless-stopped

Common mistakes

  • Using always and fighting manual stops.
  • Hiding crash loops.
  • No health checks.

Key takeaways

  • Restart policies tell Docker when to restart a container automatically: no, on-failure, always or unless-stopped.
  • Run docker <command> --help for all options.
  • Clean up unused resources regularly.

FAQ

always vs unless-stopped?

always restarts even after a manual stop when the daemon restarts; unless-stopped respects manual stops.

Where can I see all options?

Run the command with --help.

More General articles