Docker Restart and Healthcheck

Keep services alive with restart policies and HEALTHCHECK.

  • docker restart
  • healthcheck
  • unless-stopped
  • container crash
  • docker events

Docker Restart and Healthcheck

Keep services alive with restart policies and HEALTHCHECK.

Commands

CommandWhat it does
docker run --restart unless-stopped app:v1Restart after reboots and crashes
docker update --restart unless-stopped <c>Retrofit a policy onto a running container
docker inspect -f {{.State.Health.Status}} <c>Read health status
docker events --filter event=health_statusWatch health transitions live

Example

docker run -d --restart unless-stopped --name api app:v1
docker inspect -f '{{.State.Health.Status}}' api

FAQ

Which restart policy for servers?

unless-stopped: survives reboots and crashes but respects your manual stop; always is for kiosks that must never stay down.

HEALTHCHECK in Dockerfile or compose?

Either: Dockerfile bakes a default check; compose can override per environment.

Частые вопросы

Which restart policy for servers?
unless-stopped: survives reboots and crashes but respects your manual stop; always is for kiosks that must never stay down.
HEALTHCHECK in Dockerfile or compose?
Either: Dockerfile bakes a default check; compose can override per environment.

Docker