Docker Compose up --wait Fails: Inspect the Unhealthy Container
Contents
When docker compose up --wait fails in CI, inspect the service container before tearing down the project. The command can exit nonzero while the container is still running. A failed probe may already have recorded the reason in .State.Health.Log, even if the application’s own logs are empty.
Docker’s Compose CLI reference describes --wait as waiting for services to be running or healthy, streaming their logs unless --detach is set. A running service without a healthcheck has no probe to pass. For a service with a healthcheck, distinguish between a probe that has already made the container unhealthy and a wait that expired while the probe was still starting.
Capture the probe output before cleanup
Run these commands from the same Compose project, with the same project name and file options you used for startup. Replace probe with the failing service name. For a scaled service, inspect each returned ID separately.
docker compose ps --alldocker compose ps --all --quiet probe
docker inspect --format '{{.State.Status}} {{if .State.Health}}{{.State.Health.Status}}{{else}}no-healthcheck{{end}}' CONTAINER_IDdocker inspect --format '{{if .State.Health}}{{json .State.Health.Log}}{{end}}' CONTAINER_IDCheck the latest completed probe’s ExitCode and Output. If the log is empty, the probe may not have run yet. Save the startup error alongside the inspection output. The inspect result is a snapshot, so the container can change state after Compose returns.
Reproduce the two failures
In a scratch directory, save this as compose.yaml. The service’s main process stays alive while its probe deliberately fails. The interval is adjustable so you can also make the wait expire before the first probe.
services: probe: image: ubuntu:24.04 command: ["sleep", "infinity"] healthcheck: test: ["CMD-SHELL", "echo 'readiness marker missing'; exit 1"] interval: ${PROBE_INTERVAL:-1s} timeout: 1s retries: 1Run both cases in separate projects. The following loop handles the failed startup inside a conditional so diagnostics still run under set -e.
for scenario in unhealthy timeout; do case "$scenario" in unhealthy) interval=1s; limit=20 ;; timeout) interval=30s; limit=3 ;; esac
project="wait-demo-$scenario" if PROBE_INTERVAL="$interval" docker compose -p "$project" up --wait --wait-timeout "$limit"; then status=0 else status=$? fi printf '%s: exit=%s\n' "$scenario" "$status"
cid=$(docker compose -p "$project" ps --all --quiet probe) docker inspect --format '{{.State.Status}} {{.State.Health.Status}} {{json .State.Health.Log}}' "$cid" docker compose -p "$project" downdoneWith Docker Compose 5.1.3 and Docker Engine 28.4.0 on Linux arm64, both commands returned exit code 1. The inspection separated the causes.
| Case | Container state immediately after the command | Probe evidence |
|---|---|---|
| Failing probe, 20-second wait budget | running unhealthy | Exit code 1 and readiness marker missing |
| First probe scheduled beyond the 3-second wait budget | running starting | Empty probe log |
In CI, use the failed-probe output to check what the command needs inside the container, such as a binary, credentials, or an endpoint. If the log is empty and the service is still starting, compare the wait budget with the probe interval and measure when the application becomes ready. Increasing the wait budget gives a slow service more time. The probe output tells you whether it also needs a configuration fix.
If your problem is that one service starts before another is ready during ordinary Compose startup, configure the dependency’s healthcheck and service_healthy condition.
References: