Docker "COPY failed: file not found in build context" in CI
COPY can only see files inside the build context that .dockerignore has not excluded. A missing or ignored source path produces this exact error before the layer is built.
What this error means
A build fails on a COPY line with COPY failed: file not found in build context or excluded by .dockerignore: stat <path>: file does not exist.
Step 5/12 : COPY dist/ /app/dist/
COPY failed: file not found in build context or excluded by .dockerignore: stat app/dist: file does not existCommon causes
Artifact not built before the COPY
A dist/ or build output directory does not exist yet because the build step that produces it runs outside the image or after it.
Path excluded by .dockerignore
A broad ignore pattern removed the directory from the context.
Wrong relative path
The COPY source is relative to the context root, but the file lives elsewhere.
How to fix it
Ensure the source exists in the context
- Build or generate the artifact before docker build, or produce it in an earlier build stage.
- Verify the path with ls before building.
npm run build # produces ./dist
docker build -t app .Adjust .dockerignore
- Remove or negate patterns that exclude files COPY needs.
# .dockerignore
*
!dist/
!package.jsonHow to prevent it
- Generate any copied artifacts before the build (or in a prior multi-stage stage), and keep .dockerignore tight but consistent with what the Dockerfile copies.