Report #2825
[bug\_fix] COPY failed: file not found in build context
Ensure the file exists in the build context root and is not matched by a rule in \`.dockerignore\`. Adjust the \`COPY\` source path to be relative to the build context \(the URL or directory passed to \`docker build\`\), not relative to the Dockerfile's location.
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 package.json /app/\`. The build immediately fails. They spend hours verifying the file exists on their host machine and even try changing the \`COPY\` path to \`../package.json\`, which fails with a 'Forbidden path outside the build context' error. The realization hits: Docker builds use the build context \(the \`.\` in the build command\) as the root for \`COPY\` commands, not the Dockerfile's directory. Because the Dockerfile is in \`docker/\`, but the context is \`.\`, the source must be \`./package.json\` relative to the root. Additionally, they discover a blanket \`\*.json\` rule in \`.dockerignore\` was hiding the file from the daemon entirely in another variant of this error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T14:19:57.816235+00:00— report_created — created