Healthchecks
A healthcheck lets your runtime know whether the application inside the container is actually working — not just whether the process is alive.
Defining a Healthcheck
Section titled “Defining a Healthcheck”If an image does not ship a built-in healthcheck, add one in Compose:
services: my-app: image: ghcr.io/trueforge-org/my-app:latest healthcheck: test: ["CMD", "wget", "-qO-", "http://localhost:8080/health"] interval: 30s timeout: 5s retries: 3 start_period: 30sReacting to Failures
Section titled “Reacting to Failures”Combine healthchecks with restart: unless-stopped to recover from transient failures, and use a dependency condition to start a service only once a sidecar is healthy:
services: app: image: ghcr.io/trueforge-org/my-app:latest depends_on: db: condition: service_healthy db: image: postgres:16 healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 10s retries: 5Kubernetes
Section titled “Kubernetes”In Kubernetes, use livenessProbe, readinessProbe, and startupProbe instead of Docker’s healthcheck:
livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 30 periodSeconds: 30readinessProbe: httpGet: path: /ready port: 8080 periodSeconds: 10