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