Skip to content

require-restart-policy

Docker Compose services don't restart after a crash or reboot by default. Choosing between restart: always and unless-stopped.

On this page

The default restart policy is no: when a service crashes at 3 a.m. — or the host reboots after a power cut or kernel update — the container simply stays down until a human notices. This rule flags Compose services with no restart policy.

What the rule catches

compose.yaml — crash at 3 a.m., down until morning
services:
  api:
    image: acme/api:1.4.2

Scanning this file reports:

⚠ WARN [docker-doctor/require-restart-policy]
  Service 'api' has no restart policy configured. It will not restart if it crashes or if the host reboots.

Why it matters

Crashes are normal operation: OOM kills, unhandled exceptions, dropped database connections, host reboots. A restart policy is the difference between a 10-second blip and an outage that lasts until someone checks. unless-stopped is the policy that matches operational intent — it restarts on any crash and after reboot, but stays down when you deliberately stopped the service (whereas always will resurrect it at the next daemon restart, surprising whoever stopped it for maintenance).

How to fix it

Define restart: always or restart: unless-stopped (or deploy.restart_policy) so services restart on crashes or host reboot.

compose.yaml — restarts on crash and after reboot
services:
  api:
    image: acme/api:1.4.2
    restart: unless-stopped

on-failure[:max-retries] restarts only on non-zero exits, useful for one-shot jobs that should retry a bounded number of times. Restart policies handle a dead process; they can't see a process that's alive but broken — pair them with a HEALTHCHECK so unhealthy states are visible too. Docker restarts with exponential backoff, so a crash-looping service won't peg the host.

Rule details

  • Rule keydocker-doctor/require-restart-policy
  • Category — Compose
  • Default severitywarning
  • Applies to — Docker Compose files

Explain this rule from the CLI:

npx @docker-doctor/cli@latest rules explain docker-doctor/require-restart-policy

Change its severity — or turn it off — in your config file:

// docker-doctor.config.ts
export default {
  rules: {
    "docker-doctor/require-restart-policy": "off",
  },
};

Severity affects the health score: error findings cost more points than warning, and info costs the least.