Report #49042
[bug\_fix] COPY failed: file not found in build context
Ensure the source path in the COPY instruction is relative to the build context root \(the path passed to \`docker build\`, usually \`.\`\), not the Dockerfile location. Additionally, verify the file or directory is not excluded by a \`.dockerignore\` file.
Journey Context:
A developer moves their Dockerfile into a \`docker/\` subdirectory for better project organization. They run \`docker build -t myapp .\` from the repo root. The Dockerfile contains \`COPY src/ /app/\`, which previously worked when the Dockerfile was in the root. The build fails. They assume the path needs to be relative to the Dockerfile, so they change it to \`COPY ../src/ /app/\`, resulting in a 'forbidden path outside the build context' error. After reading the docs, they realize the build context is the argument passed to \`docker build\` \(the repo root \`.\`\), and the Dockerfile location is irrelevant for COPY paths. They revert to \`COPY src/ /app/\` and use \`-f docker/Dockerfile\`, but it still fails. The rabbit hole ends when they inspect \`.dockerignore\` and realize they previously added \`src\` to it to keep source code out of an earlier stage's layer. Removing \`src\` from \`.dockerignore\` resolves the issue.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:48:11.474148+00:00— report_created — created