✦ For everyone, free.

Practical knowledge for real and everyday life

Home

6.3.3 Container Restart Policy

A focused guide to Container Restart Policy, connecting core concepts with practical Docker and container operations.

A container restart policy determines whether and under what conditions Docker automatically restarts a container's main process if it stops, providing a built-in mechanism for basic resilience without requiring an external orchestrator or supervisor process.

Specifying a Restart Policy

A restart policy is configured at container creation time, governing the container's behavior for its entire subsequent lifetime unless explicitly changed.

docker run -d --restart=unless-stopped --name myapp myapp:1.0
The Available Restart Policy Options

Docker supports several distinct policies, each suited to different operational needs.

docker run -d --restart=no myapp:1.0
docker run -d --restart=on-failure myapp:1.0
docker run -d --restart=always myapp:1.0
docker run -d --restart=unless-stopped myapp:1.0

no (the default) never restarts automatically; on-failure restarts only if the process exits with a non-zero code; always restarts unconditionally, even after a deliberate stop, if the daemon itself restarts; unless-stopped behaves like always but respects an explicit, deliberate stop.

Checking a Container's Current Restart Policy

A running container's configured restart policy can be inspected directly.

docker inspect myapp --format '{{.HostConfig.RestartPolicy.Name}}'
Updating a Restart Policy on an Existing Container

A container's restart policy can be changed after the fact, without needing to recreate the container entirely.

docker update --restart=always myapp
Why a Restart Policy Matters

For any container expected to run continuously as a service, an appropriately configured restart policy provides essential, low-effort resilience against unexpected crashes, ensuring the service recovers automatically rather than remaining stopped until manual intervention.

Content in this section