Skip to content

/errors/docker-compose/depends-on-undefined-service

Docker Compose: service "web" depends on undefined service "db"

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · Docker Compose version v5.6.0updated 2026-10-20
tool
Docker Compose
exit code
1
versions
Docker Compose v2, Docker Compose v5
os
any

Compose validates the whole project before it starts anything. If a service lists another one in depends_on and that service does not exist in the merged configuration, every command (up, config, ps …) fails with service "web" depends on undefined service "db": invalid compose project.

Reproduce it

docker compose config (here the standalone docker-compose binary) validates the file without needing a Docker daemon:

bash
cat > compose.yaml <<'EOF'
name: demo
services:
  web:
    image: nginx:1.29
    depends_on:
      - db
EOF
docker-compose config

Output · exit 1

service "web" depends on undefined service "db": invalid compose project

Fix: define the service, or load the file that does

compose.yaml
name: demo
services:
  web:
    image: nginx:1.29
    depends_on:
      - db
  db:
    image: postgres:18

If db lives in another file, pass both: docker compose -f compose.yaml -f compose.db.yaml up. Files are merged in order before validation.

Optional dependencies

When the dependency may legitimately be absent (for example it is in a profile that is not always enabled), Compose 2.20 and later accept required: false:

yaml
services:
  web:
    image: nginx:1.29
    depends_on:
      db:
        condition: service_started
        required: false

Sources