How to add a Docker healthcheck

Healthcheck defined · docker.healthcheck

Why it matters

Without a healthcheck the orchestrator only knows the process is alive, not that it answers. A hung container keeps receiving traffic instead of being restarted.

How to fix it

What to do: Add a healthcheck to docker-compose.yml.

services:
web:
image: myapp:latest
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s


Also add a /health/ endpoint to your app returning HTTP 200.

Does your repository pass this check?

Free for public GitHub repositories, no account needed. 50+ DevOps and security checks in about ten seconds.

Related checks