Compose startup dependencies with depends_on
Depends_on expresses a startup dependency between services. Short syntax orders startup but does not establish application readiness. In this fixture the web service starts an HTTP listener after a brief initialization; client uses long-form condition: service_healthy so Compose waits for the web health probe before starting client. service_started expresses startup order and service_completed_successfully is useful for a finite initialization task. These conditions are about initial coordination. Client applications still need bounded retries and failure handling after startup, because a dependency can fail later.
Read the configuration
services: web: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - sleep 3; mkdir -p /tmp/site && printf 'ready-v13\n' > /tmp/site/index.html && exec httpd -f -p 8080 -h /tmp/site networks: - app healthcheck: test: - CMD - wget - -T - '2' - -q - -O - /dev/null - http://127.0.0.1:8080/ interval: 2s timeout: 3s retries: 5 client: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sh - -c - exec sleep 300 networks: - app depends_on: web: condition: service_healthynetworks: app: internal: trueManual lab
Manual lab only, not browser execution. Use a fresh approved disposable Linux VM with external egress blocked and a local Docker context. Check docker context show, docker version and docker compose version; verify support for each flag and field. Preload and verify the native-platform BusyBox 1.37 digest, entrypoint and required applets; the tag is mutable. Ensure bm-v13 project/image/volume names are unused and no inherited COMPOSE_PROFILES or BM13 variables interfere. Use only the synthetic files here, on a disposable copy. File-backed config/secret mounts are limited to these exact files; verify UID 10001 can read them. No public ports, external pulls/pushes, real secrets or host directory mounts. Run each command individually; stop on unexpected failures, perform scoped cleanup and dispose of the VM. Explicit negative probes are expected to fail. All results below are predictions. Before Engine requests, verify the effective endpoint including DOCKER_HOST and DOCKER_CONTEXT; a project name does not select the daemon. Review inherited COMPOSE_ENV_FILES, COMPOSE_DISABLE_ENV_FILE, profile and project settings. Use a clean shell and the exact fixture directory. Inspect only synthetic config, logs and files. If a build is required, verify the effective builder can resolve the approved local base without egress; stop if build fails, never reuse a stale tag.
Open lab-fixtures/docker-compose-configuration/07-depends-on/ in the extracted archive and run from a disposable copy of that folder.
docker compose -f compose.yaml -p bm-v13-depends-on config --quietdocker compose -f compose.yaml -p bm-v13-depends-on up --wait --wait-timeout 25 --no-build --pull neverdocker compose -f compose.yaml -p bm-v13-depends-on exec -T client wget -T 3 -qO- http://web:8080/docker compose -f compose.yaml -p bm-v13-depends-on stop -t 5 webdocker compose -f compose.yaml -p bm-v13-depends-on ps# Expected failure: web is stoppeddocker compose -f compose.yaml -p bm-v13-depends-on exec -T client wget -T 3 -qO- http://web:8080/docker compose -f compose.yaml -p bm-v13-depends-on up --wait --wait-timeout 25 --no-build --pull neverdocker compose -f compose.yaml -p bm-v13-depends-on exec -T client wget -T 3 -qO- http://web:8080/After the bounded wait, client should retrieve ready-v13. Stopping web should leave client running, but its next HTTP probe should fail. Starting web again and waiting for readiness should restore the probe. This is a planned behavior test, not observed execution. Check client identity and state throughout the negative phase. Diagnose the failed HTTP request while web is stopped, then verify the exact ready-v13 response after recovery. The initial readiness condition is not continuous supervision of client behavior.
Clean only this disposable project. No global prune or force removal. Verify the project is empty. Retain the base image.
docker compose -f compose.yaml -p bm-v13-depends-on downdocker compose -f compose.yaml -p bm-v13-depends-on ps -aCommon mistake
Do not fix a readiness race by guessing a long sleep in every consumer. Use a meaningful health probe plus application-level handling of later failures.
Manual practice
For an initialization task that exits successfully, choose the dependency condition and explain why waiting for a permanently running process would be inappropriate.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Compose startup dependencies with depends_on — Knowledge check
Reason about the Compose configuration and its consequences.
Which condition waits for the health probe?
Which fits a successful finite migration task?
What happens if web fails later?