Skip to content
Latchkey

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.

docker
[+] Building 12.3s (8/14)
failed to solve: failed to compute cache key: "/package.json": not found
Service 'web' failed to build: COPY failed

Common 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

  1. Look above the compose failure line for the real Dockerfile error and fix that.
  2. Build the single service with plain progress to see full output.
Terminal
docker compose build --progress=plain web

Fix the build config

  1. Confirm build.context and build.dockerfile resolve to real paths.
docker-compose.yml
services:
  web:
    build:
      context: ./web
      dockerfile: Dockerfile

How 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →