Report #71202
[bug\_fix] COPY failed: file not found in build context despite explicitly un-ignoring the file in .dockerignore using the \! exception prefix.
Reorder .dockerignore rules so that broad exclusions do not ignore the parent directory of a file you intend to un-ignore, or avoid ignoring the parent directory entirely if you need to include sub-items.
Journey Context:
A developer wants to ignore everything in their repo except the dist/ folder to keep the build context small. They write a .dockerignore with \`\*\` on line 1 and \`\!dist/\` on line 2. The \`COPY dist/ /app/dist/\` fails, claiming the file doesn't exist. They verify the folder exists locally. They read the Docker documentation and discover a critical, often-missed rule: due to Go's filepath.Match behavior, if a parent directory is ignored, its children cannot be un-ignored. Because \`\*\` ignores the root directory itself, the \`\!dist/\` exception is useless. The fix works by not ignoring the root directory itself, but ignoring specific top-level items instead \(e.g., ignoring \`\*.md\`, \`.git\`, \`src/\`, but leaving \`dist/\` alone\), allowing the exception to apply to a directory that wasn't blanket-excluded at a higher level.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:05:33.539469+00:00— report_created — created