Interview Prep/Docker/Networking and Compose

Compose healthcheck for a service depends on the app being ready, not just the port open.

IntermediateScenarioNetworking and Compose
Answer

Situation read → A TCP-open port can still return 503.

What I'd do →

healthcheck:
  test: ["CMD", "curl", "-fsS", "http://localhost:8080/healthz"]
  interval: 10s
  timeout: 3s
  retries: 5
  start_period: 30s

Make /healthz check dependencies (cache or DB) with care, since cascading failures can occur.

Why → -f makes curl fail on HTTP errors; start_period avoids false negatives during boot.

Interview tip → Separate liveness from readiness semantics.

All Docker questions Roadmap: Docker & containers

More on Networking and Compose