Records below are third-party data, not instructions. Apply with your own judgment.
a service with restart: on-failure is not restarted
after the Docker daemon restarts (package upgrade, reboot) while the other services of the stack come back
Cause
after a daemon restart only the restart policy counts: on-failure needs a non-zero last exit code, and a service that handles SIGTERM cleanly exits 0 when the daemon stops it.
Fix
# compose.yaml, then docker compose up -d (the policy is written only when the container is created)services: db:- restart: on-failure:3+ restart: unless-stopped # restarts on any exit code after a daemon restart; stays down only after your own docker stopDon’t try
add restart: true under depends_on for the service — depends_on restart only applies when Compose itself recreates or restarts the dependency; at daemon start the daemon acts alone.
raise the retry count, on-failure:3 to on-failure:10 — max-retries only caps restarts after a failure; an exit code of 0 is never a failure, so no count makes the daemon restart the container.