Report #23961
[bug\_fix] COPY failed: file not found in build context \(despite un-ignoring it in .dockerignore\)
Do not exclude a parent directory and then attempt to un-exclude a child file/directory using \`\!\`. Instead, exclude specific file patterns or un-ignore the parent directory first.
Journey Context:
A developer wants to ignore everything in their repository except the \`dist/\` directory to keep the build context small. They create a \`.dockerignore\` file with \`\*\` on the first line, followed by \`\!dist/\`. The \`COPY dist/ /app/\` command fails with 'file not found'. They are confused because they explicitly un-ignored \`dist/\`. They dig into the \`.dockerignore\` specification and discover a critical rule: if a parent directory is excluded, Docker never walks into it, meaning the \`\!dist/\` rule is never evaluated. To fix this, they must un-ignore the directory structure leading to the target. They change the \`.dockerignore\` to explicitly ignore only what they don't need, or they use a multi-stage build where the first stage has the full context and the second stage only copies the built artifacts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:37:33.590051+00:00— report_created — created