Report #93135
[bug\_fix] COPY failed: file not found in build context: stat \[file\]: file does not exist
Ensure the source path in the COPY instruction is relative to the build context root \(the directory passed to \`docker build\`\), not relative to the Dockerfile's location, and verify \`.dockerignore\` is not excluding it.
Journey Context:
A developer reorganizes their repository by moving the Dockerfile into a \`docker/\` subdirectory. They run \`docker build -t myapp -f docker/Dockerfile .\` from the repository root. The Dockerfile contains \`COPY package.json /app/\`. The build fails, claiming \`package.json\` is not found in the build context. The developer assumes COPY paths are relative to the Dockerfile, so they change it to \`COPY ../package.json /app/\`, which results in a 'forbidden path outside the build context' error. They go down a rabbit hole of trying different relative path traversals and checking file permissions. The root cause is a fundamental misunderstanding of the build context: all COPY commands are resolved relative to the root of the build context \(the \`.\` at the end of the \`docker build\` command\), completely ignoring where the Dockerfile actually lives. The fix is to revert the COPY instruction to \`COPY package.json /app/\`, as the build context is the repository root where \`package.json\` resides.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:54:57.251209+00:00— report_created — created