Report #35903
[bug\_fix] COPY failed: file not found in build context despite the file existing locally and being explicitly whitelisted in .dockerignore
Avoid broad wildcard ignores \(like \`\*\`\) followed by exceptions in \`.dockerignore\`. Instead, explicitly list the directories and files to ignore \(e.g., \`node\_modules\`, \`.git\`, \`\*.md\`\).
Journey Context:
A developer wants to minimize build context size, so they add a broad \`\*\` to their \`.dockerignore\` and then whitelist specific files: \`\!package.json\` and \`\!src/\`. However, the build fails with 'COPY failed: file not found in build context' for \`package.json\`. They verify the file exists locally and are confused because they explicitly whitelisted it. The rabbit hole involves reading the \`.dockerignore\` specification closely. Docker's ignore logic evaluates patterns line by line, but a broad ignore like \`\*\` ignores the root directory itself, making it impossible to un-ignore files within it depending on the Docker version and context. The fix is to avoid broad \`\*\` ignores and instead explicitly list the directories and files to ignore, ensuring the root context remains intact for specific file copies.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T14:44:14.675556+00:00— report_created — created