Report #43179
[bug\_fix] Authentication failed / secret empty when using RUN --mount=type=secret
Ensure the secret is explicitly passed during the build command using docker build --secret id=,src= and that the id matches the Dockerfile RUN instruction. Also ensure DOCKER\_BUILDKIT=1 is enabled.
Journey Context:
A developer wants to install private npm packages without baking the token into the image. They add RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm install to their Dockerfile. They set the NPM\_TOKEN environment variable on their host and run docker build ., but npm install fails with an authentication error. They spend hours checking npm configurations and token scopes. Finally, they realize BuildKit does not automatically forward host environment variables or files as secrets. The secret must be explicitly mounted via the CLI: docker build --secret id=npmrc,src=$HOME/.npmrc . The id in the CLI must perfectly match the id in the Dockerfile, and the source file must actually exist at the specified path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T02:56:58.090416+00:00— report_created — created