/errors/docker-compose/depends-on-undefined-service
Docker Compose: service "web" depends on undefined service "db"
- 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:
cat > compose.yaml <<'EOF'
name: demo
services:
web:
image: nginx:1.29
depends_on:
- db
EOF
docker-compose configOutput · exit 1
service "web" depends on undefined service "db": invalid compose project
Fix: define the service, or load the file that does
name: demo
services:
web:
image: nginx:1.29
depends_on:
- db
db:
image: postgres:18If 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:
services:
web:
image: nginx:1.29
depends_on:
db:
condition: service_started
required: false