Docker Compose check · low

Services without a restart policy

Without a restart policy Docker uses "no": a container that crashes, or that was running when the host or Docker daemon restarted, stays stopped until someone starts it. The explainer flags services with neither restart nor deploy.restart_policy as low. For long-running services, restart: unless-stopped is a common default.

$ explain docker-compose.yml
! app has no restart policy low
line 2
fix: see below
$ 

What the free Docker Compose explainer reports on the risky example below.

Why it matters

Crashes happen: an out-of-memory kill, an unhandled error, a dependency that was briefly unavailable. Without a policy, one such event leaves the service down until it is noticed.

After a host reboot, Docker brings back containers whose policy says to, and leaves the others stopped.

The policy is also part of what the file documents: a reader can see which services are meant to stay up.

Risky and safer docker-compose.yml

Riskydocker-compose.yml
services:
  app:
    image: example/app:1.4.2
    mem_limit: 512m
Saferdocker-compose.yml
services:
  app:
    image: example/app:1.4.2
    restart: unless-stopped
    mem_limit: 512m

How to fix it

  • Add restart: unless-stopped to long-running services: they come back after crashes and daemon restarts, but stay stopped if you stopped them by hand.
  • Use restart: on-failure for jobs that should retry on errors but not run again after a clean exit.
  • For one-off tasks such as migrations, set restart: "no" explicitly so the choice is visible; the explainer accepts that as a policy.

When it's acceptable

  • One-off or batch containers that should run once and exit.
  • Stacks managed by something else that restarts them, such as a process supervisor or an orchestrator.

Check your own docker-compose.yml

The risky example is loaded below. Paste your own file to check it for this and every other Docker Compose rule. It runs in your browser; nothing is uploaded.

docker-compose.yml

Parsed in your browser. Nothing is uploaded.

Explanation

1 service0 networks0 volumes1 low

Top level

appexample/app:1.4.2

Also worth a look

If the process crashes or the host reboots, the service stays down until someone notices.

Safer: Set restart: unless-stopped (or a deploy.restart_policy).

Questions

What is the default restart policy in docker-compose?

"no": Docker does not restart the container automatically, whether it crashed or the host rebooted.

What is the difference between always and unless-stopped?

Both restart the container after it exits. With always, a container you stopped manually starts again when the Docker daemon restarts; with unless-stopped it stays stopped.

Does deploy.restart_policy count as a restart policy?

Yes. The explainer accepts either restart or deploy.restart_policy on the service.