Report #10527
[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\`, typically \`.\`\), not relative to the Dockerfile's location. Verify the file exists in the context and is not excluded by a \`.dockerignore\` file.
Journey Context:
A developer creates a Dockerfile inside a subdirectory \(e.g., \`api/Dockerfile\`\) and runs \`docker build -f api/Dockerfile .\` from the repository root. The Dockerfile contains \`COPY package.json /app/\`. The build fails. The developer falls down a rabbit hole of checking the local filesystem, confirming \`package.json\` exists right next to the Dockerfile. They might even try absolute paths. The breakthrough comes when they realize Docker's COPY instruction resolves paths against the \*build context\* \(the \`.\` argument\), not the Dockerfile's directory. Since the build context is the repo root, Docker looks for \`./package.json\` at the root, not in \`./api/\`. Changing the instruction to \`COPY api/package.json /app/\` or moving the Dockerfile to the root fixes it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:54:07.360967+00:00— report_created — created