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.
More on Networking and Compose
Containers on the default bridge cannot resolve each other by name. Why, and what do you do?BeginnerHow do you expose a container only to the local host, not the internet?BeginnerDesign a Compose file for web + api + postgres + redis with correct startup ordering.IntermediateFrontend must reach the API but not the database. Segment the network.IntermediateA container needs to call a service running on the Docker host.BeginnerWhen would you use `--network host`?Intermediate