Skip to content

depends on undefined service: dependency on a service in a profile

Containertested on Docker 29.9.0, Docker Compose 5.6.0

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

Set required: false under tracer: in depends_on – the same up then exits 0 and worker starts without tracer. Or remove the service and the dependency and check with docker compose config -q.

Don't: Remove the profile so the debug service always runs – then a tool meant only for debugging starts in every environment.

▶
Break it yourself and find it – free
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.

Related error patterns

More