Report #88505
[bug\_fix] Private package registry authentication fails during docker build despite using BuildKit secrets, because the secret file is empty or inaccessible inside the RUN step
Ensure the \`id\` in the Dockerfile \`--mount=type=secret,id=...\` exactly matches the \`id\` in the \`docker build --secret id=...,src=...\` flag, and verify the source file exists on the host.
Journey Context:
A developer tries to securely pass an \`.npmrc\` file to a \`docker build\` to install private npm packages. They add \`RUN --mount=type=secret,id=npmrc npm install\` to the Dockerfile and run \`docker build .\`. The build fails with a 401 Unauthorized. They assume the secret mounting isn't working and try to \`ENV\` the token instead, which works but is insecure. They go back to secrets and realize they forgot to pass the \`--secret\` flag to the \`docker build\` command, or they used a mismatched \`id\` \(e.g., \`id=npm\` in the CLI but \`id=npmrc\` in the Dockerfile\). Without the exact ID match and the CLI flag, BuildKit mounts an empty file, causing the auth failure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:08:17.891145+00:00— report_created — created