depends_on & health conditions

Wait for a useful dependency state

Lesson 14 of 20 · 12 min · Module 5: Readiness and runtime boundaries

Startup order and application readiness are different promises.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Name the readiness dependency
  • Provide the corresponding probe

The idea

Compose describes services and their relationships as YAML mappings and sequences. Read the whole service graph, including access and storage boundaries.

01Name the readiness dependency

A started container may still be initializing. A service_healthy dependency uses the dependency healthcheck rather than assuming that process startup means readiness.

02Provide the corresponding probe

The health condition needs an actual healthcheck definition on cache. The lab rejects healthy dependencies whose target has no probe.

03Retain application resilience

Startup gating does not guarantee a dependency will stay available. Real clients still need appropriate timeouts and recovery behavior during operation.

Your turn

Define api using notes:1.0 and cache using redis:7-alpine. Give cache healthcheck test ["CMD","redis-cli","ping"]. Make api depend on cache with condition service_healthy.

What the checks look for

  • Waits for a healthy cache
  • Declares a Redis probe
Try it in the editor →

Take this with you

Use a meaningful readiness condition while keeping clients resilient.

Go a little further

Create a dependency cycle and read the validation error.

Learn Docker & Containers for free

20 short lessons with real code and instant checks.

See the whole course →