📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Docker Healthchecks

Healthchecks

5 min read Quiz at the end
Add healthchecks so Docker and Compose know when a service is ready before routing traffic.

Container Healthchecks

# In Dockerfile
HEALTHCHECK --interval=30s --timeout=10s --retries=3     CMD curl -f http://localhost:3000/health || exit 1

# In docker-compose.yml
services:
  api:
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
      interval: 30s
      timeout: 10s
      start_period: 10s
      retries: 3

# depends_on with health condition
depends_on:
  api:
    condition: service_healthy

# Check status
docker inspect --format={{.State.Health.Status}} mycontainer
Topic Quiz · 2 questions

Test your understanding before moving on

1. What exit code makes a healthcheck report unhealthy?
💡 Any non-zero exit code from the healthcheck command marks the container as unhealthy.
2. What does start_period do in a healthcheck?
💡 start_period gives slow-starting containers time to initialise before health failures are counted.