❤️ Is Your Container Actually Working?
Container running but app crashed? Health checks test app responsiveness. Automatically restart unhealthy containers.
📝 Health Check in Dockerfile
# Web app HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD curl -f http://localhost/ || exit 1 # Database HEALTHCHECK --interval=30s --timeout=10s --retries=5 \ CMD pg_isready -U postgres || exit 1 # Redis HEALTHCHECK --interval=30s --timeout=3s --retries=3 \ CMD redis-cli ping || exit 1
🎯 Docker Compose Healthcheck
services:
app:
image: myapp
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
depends_on:
postgres:
condition: service_healthy
💡 Commands
- docker ps (shows health status)
- docker inspect –format='{{json .State.Health}}’ container_name
- docker events (see health events)
- Kubernetes liveness probes (alternative)
“Container was running but app dead. No health check = nobody knew. Added health check, container restarted. Downtime eliminated.”
