Production Docker · 8 min read · Intermediate
Healthchecks & Restart Policies
Keep production containers resilient with HEALTHCHECK probes, unless-stopped restart policies, and depends_on conditions.
What you'll learn
- Add a HEALTHCHECK instruction probing /api/health
- Configure restart: unless-stopped so containers recover after crashes or server reboots
- Wait for a healthy database before starting the API in Docker Compose
A container process can be “running” (Up) even while the app inside is deadlocked or failing requests. Adding a HEALTHCHECK tells Docker to periodically test /api/health and mark the container healthy or unhealthy. Pairing that with restart: unless-stopped ensures services bounce back automatically after a server reboot.
Fill-in-the-Blank Exercise
Auto-Restart Policy
Configure a container to restart automatically unless manually stopped.
docker run -d -- -p 8787:8787 devpath-api:1.0Live Healthcheck Config Lab
Bashhealthcheck.sh
Expected OutputClick “Run Live” to compile with GNU Bash
HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD curl -fsS http://127.0.0.1:8787/api/health || exit 1
Check Your Understanding
Score: 0 / 1
1. What does `restart: unless-stopped` do in Docker Compose?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.