Docker Compose "service failed to build" in CI
Compose reports that a service could not build, but the real error is in the wrapped Dockerfile build above it: a failed COPY, RUN, or a missing context, surfaced through compose.
What this error means
A docker compose build or up --build fails with failed to build: <service> or Service <name> failed to build. The underlying build error appears just above.
[+] Building 12.3s (8/14)
failed to solve: failed to compute cache key: "/package.json": not found
Service 'web' failed to build: COPY failedCommon causes
Underlying Dockerfile build failed
A COPY/RUN/parse error in the service Dockerfile is the true failure; compose only wraps it.
Wrong build context or dockerfile path
The service build.context or build.dockerfile in compose points at the wrong location.
How to fix it
Read the wrapped build error
- Look above the compose failure line for the real Dockerfile error and fix that.
- Build the single service with plain progress to see full output.
docker compose build --progress=plain webFix the build config
- Confirm build.context and build.dockerfile resolve to real paths.
services:
web:
build:
context: ./web
dockerfile: DockerfileHow to prevent it
- Treat compose build failures as Dockerfile failures: read the wrapped error and keep build.context/dockerfile paths correct. This is deterministic, not transient.