Report #66414
[bug\_fix] Authentication failure \(401 Unauthorized or 'Permission denied'\) during a RUN step that uses \`--mount=type=secret\`, despite passing the secret correctly to the build command.
Explicitly set the \`target\` path in the mount instruction \(e.g., \`--mount=type=secret,id=mysecret,target=/root/.secret\`\) and configure the tool to read from that exact path.
Journey Context:
A developer wants to install private npm packages without baking credentials into the image. They add \`RUN --mount=type=secret,id=npmrc ...\` and run \`docker build --secret id=npmrc,src=$HOME/.npmrc .\`. The build fails with authentication errors. They echo the secret file inside the RUN command and find it empty or missing. The rabbit hole involves checking host file permissions and trying different secret IDs. The root cause is that by default, BuildKit mounts the secret at \`/run/secrets/\`, but the package manager \(like npm or pip\) expects the credentials at a specific, conventional path \(like \`/root/.npmrc\` or via an environment variable\). The fix is to explicitly specify the \`target\` mount path in the Dockerfile instruction so the secret appears exactly where the tool expects it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:57:28.303920+00:00— report_created — created