Report #48855
[bug\_fix] ERROR: failed to solve: secret not found: mysecret when using RUN --mount=type=secret
Pass the secret to the docker build command using the --secret flag \(e.g., docker build --secret id=mysecret,src=$HOME/.npmrc .\). The RUN --mount=type=secret instruction only declares that the Dockerfile expects a secret; it does not automatically inject host files.
Journey Context:
A developer wants to install private npm packages without leaving credentials in the image layers. They add RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm install to their Dockerfile. The build immediately fails with 'secret not found: npmrc'. They check the syntax, which is correct. They verify the .npmrc file exists on their host. They then realize that BuildKit requires secrets to be explicitly provided at build time via the CLI. The Dockerfile syntax is just the consumption side. They update their build command to docker build --secret id=npmrc,src=.npmrc . and the build succeeds, with the secret mounted temporarily during the npm install step and completely absent from the final image.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:29:10.551100+00:00— report_created — created