Containers Without a Restart Policy Stay Down After a Host Reboot

In progress Docker

Docker's default restart policy is no: a container that exits, crashes, or was running when the host rebooted stays stopped until someone starts it. On a VPS that reboots for kernel updates, a Compose stack without restart: comes back as a server with Docker running and no applications. Behind a shared reverse proxy, the symptom isn't even "connection refused" but proxy errors that look like TLS problems.

The Four Policies

Policy Restarts after a crash Restarts after a daemon or host restart After docker stop
no (default) no no stays stopped
on-failure[:N] only on a non-zero exit, up to N times yes, if it had not been stopped manually stays stopped
always yes yes stays stopped until the daemon restarts, then comes back
unless-stopped yes yes, unless it was stopped manually stays stopped, even across daemon restarts
services:
  web:
    image: myapp:1.4.2
    restart: unless-stopped
  db:
    image: postgres:16
    restart: unless-stopped

What a Missing Policy Looks Like Behind nginx-proxy

With a shared proxy that discovers backends on a common network, a backend left in Exited is dropped from the proxy's configuration:

  • HTTP requests get 503 Service Temporarily Unavailable;
  • HTTPS requests can fail with ERR_SSL_UNRECOGNIZED_NAME_ALERT, because the proxy no longer has a server (and certificate) for that host name.

A restart policy restarts the process; it doesn't make it healthy. Add a healthcheck so docker ps and dependent services can tell a running-but-broken container from a working one.

References

Review cards

Flashcard Why might a container with a 'no' restart policy not start after a host reboot?

Because Docker's default restart policy is 'no', which means the container stays stopped after a crash or host reboot until manually started.

Flashcard What is the difference between the always and unless-stopped restart policies?

Both restart a container after crashes and reboots. After a manual docker stop, always starts it again at the next daemon restart; unless-stopped leaves it stopped.

Quiz After a VPS reboot, a site behind nginx-proxy fails with ERR_SSL_UNRECOGNIZED_NAME_ALERT. What do you check first?
  • Renew the site's certificate
  • docker ps -a: whether the site's container is stopped
  • The domain's DNS record
  • Whether port 443 is open

The proxy only serves names whose containers it can see. A backend without a restart policy stays stopped after the reboot, so the proxy drops its server and certificate.

Flashcard What should be done to ensure a container is healthy after a restart?

Add a healthcheck so 'docker ps' and dependent services can distinguish a running-but-broken container from a working one.