Report #7858
[bug\_fix] COPY failed: file not found in build context despite the file clearly existing in the project directory on disk
Inspect .dockerignore for patterns that exclude the needed files. Common culprits include broad patterns like \`\*\*/.env\*\`, \`\*.json\`, or \`\*\*/secrets\*\`. Add exception patterns \(lines starting with \`\!\`\) or narrow the exclusion rules to allow the required files into the build context.
Journey Context:
A developer adds \`COPY .env /app/.env\` to their Dockerfile. The build fails with 'file not found in build context' even though .env exists on disk. They verify the path repeatedly, check file permissions, try absolute paths, and even move the file — all failing. After 30 minutes, they discover their .dockerignore contains \`\*\*/.env\*\` which excludes all .env files from the build context before it reaches the Docker daemon. The file is stripped out before COPY ever sees it. This is especially insidious because the error message never mentions .dockerignore. They add \`\!.env\` as an exception line in .dockerignore \(after the exclusion pattern\) and the build succeeds. This pattern recurs with .gitignore-derived .dockerignore files that silently exclude config files, test fixtures, or asset directories.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T03:51:56.989654+00:00— report_created — created