Skip to content
BENIBIX Learn

Container Restart Policy

Infrastructure📦 ContainersRuntimes and Tools

Also known as Restart Policy, docker run --restart, restart: unless-stopped

A rule for whether a stopped box should start up again.

Think of it like

Think of it like a toy that stands back up each time it falls over.

Example

Emma runs her app with --restart unless-stopped. The server reboots at night for updates, and the app is back up before anyone notices.

Why it matters

Without one, a crash or reboot leaves the app down until someone notices. It is the simplest way for a service to heal itself.

Definition

A restart policy tells Docker what to do when a container stops. The default, no, leaves it stopped. on-failure starts it again only after an error. always starts it again whenever it stops. unless-stopped does the same, unless you stopped it yourself. The policy is how a container comes back after a crash or a reboot.

Example code

bash
docker run -d --restart unless-stopped --name app myapp
This box comes back after a crash or a reboot. It stays off if Emma stops it.
The curved arrow is the restart policy. It says if a stopped box runs again.

Common mistake

Leaving the default on a server. The default is no, so nothing comes back after a reboot.

Key takeaways

  1. 1
    Default is no. A stopped container stays stopped.
  2. 2
    Four choices. no, on-failure, always, unless-stopped.
  3. 3
    Back after reboots. always and unless-stopped return.