Services with profiles only start when their profile is active. If a normal service depends on such a service via depends_on, Compose cannot find it without the profile – and rejects the whole project before any container starts.
Symptom
docker compose up -d --wait; echo "Exit: $?" service "worker" depends on undefined service "tracer": invalid compose project Exit: 1
The tracer service is only meant for debugging and sits in the debug profile.
Diagnosis
In the compose.yaml worker depends on tracer, and tracer sits in the debug profile.
depends_on:
api:
condition: service_healthy
tracer:
condition: service_started
tracer:
image: postgres:18.6-alpine
profiles: [debug]
Causes
profiles: [debug]Service only in a profile
Without --profile debug, tracer is not part of the project. The dependency points nowhere.
depends_onDependencies are mandatory by default
Every entry under depends_on must exist, otherwise the project is invalid.
Fix
Don't: Remove the profile so the debug service always runs – then a tool meant only for debugging starts in every environment.
Docker Compose hands-on, Day 5: start order with depends_on, health checks and up --wait.
Go to day 5 →
FAQ
How do I check a compose.yaml without starting anything?
With docker compose config -q – it reports errors and prints nothing otherwise.
Does depends_on restart the dependent service when it becomes unhealthy?
No. Docker does not restart unhealthy containers; depends_on only controls the start order.