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
| Command | What it does |
|---|---|
docker run --restart unless-stopped app:v1 | Restart 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_status | Watch 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.
Câu hỏi thường gặp
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
Docker Install and Setup
Verify the Docker engine, configure context, and check versions.
Docker Images
Pull, list, tag, inspect, and remove images confidently.
Docker Containers
Run, list, stop, and clean up containers in daily work.
Docker Run Options
The flags that matter: detach, ports, env, volumes, limits.