COPY failed: file not found in build context / "/app/x": not found
The Dockerfile COPY refers to a path outside the build context, excluded by .dockerignore, or relative to the wrong directory.
Seen on:
Docker
Meaning
Docker can only copy files from the build context — the directory you pass to docker build (often .). Paths are relative to that context, not to the Dockerfile, and .. can’t escape it.
Common causes
- File excluded by
.dockerignore - Build run from a different directory than expected (context path)
- Path with
../pointing outside the context - Case mismatch or file not committed in CI checkout
- Compose
build.contextset to a subfolder
⚡ Quick fix
- Run the build from the project root:
docker build -f docker/Dockerfile . - Remove the path from .dockerignore (or add a
!pathexception) - Move shared files inside the context or widen the context
Detailed fix by platform
Docker
- Compose with an explicit context:yaml
services: api: build: context: . # project root = what COPY can see dockerfile: docker/api.Dockerfile
How to diagnose
- Context — Which directory is the build context?
- Ignore — Is the file matched by .dockerignore?
- Path — Is the COPY source relative to the context?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026