Docker Compose "build context path does not exist" in CI
A service build: context is resolved relative to the compose file's directory. When that path does not exist - a wrong relative path, a checkout that did not include the directory, or running compose from the wrong place - Compose cannot prepare the context and the build fails.
What this error means
A docker compose build/up fails with unable to prepare context: path "<dir>" not found. The build context directory is missing relative to the compose file.
docker
unable to prepare context: path "/workspace/services/api" not foundCommon causes
A wrong relative build context
The context: path does not resolve to an existing directory relative to the compose file.
The directory is absent in the checkout
A sparse or partial checkout may not include the service's build directory.
How to fix it
Point the context at the real directory
- Set
contextto the correct path relative to the compose file. - Confirm it exists before building.
docker-compose.yml
services:
api:
build:
context: ./services/api
dockerfile: DockerfileVerify the path and working directory in CI
- List the context directory and run compose from the compose file's location.
Terminal
ls -la services/api
docker compose -f docker-compose.yml build apiHow to prevent it
- Use correct context paths relative to the compose file.
- Ensure the checkout includes all build directories.
- Run compose from the directory holding the compose file.
Related guides
Docker Compose "service failed to build" in CIFix the Docker Compose "service ... failed to build" error in CI, where a service image build fails and the r…
Docker "could not find named context" - Fix --build-context in CIFix BuildKit "failed to solve: could not find named context <name>" in CI - a COPY --from / FROM referencing…
Docker Compose Bind Mount "source path does not exist" in CIFix Docker Compose "bind source path does not exist" / "are you trying to mount a directory onto a file" in C…