Report #47183
[bug\_fix] Secret file is empty or missing inside RUN instruction despite using --mount=type=secret
Pass the secret to the build command using --secret id=mysecret,src=./secret.txt and mount it in the Dockerfile using RUN --mount=type=secret,id=mysecret,target=/run/secrets/mysecret ensuring the ids match exactly.
Journey Context:
A developer tries to use BuildKit secrets to pass an SSH key or npm token. They add RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm install to the Dockerfile. The build fails with an npm authentication error. They check the file on the host and it's fine. The issue is that they only defined the mount in the Dockerfile but forgot to pass the actual secret from the host during the docker build command, or they used a mismatched id. BuildKit requires a matching pair: the id in the Dockerfile must match the id in the docker build --secret flag. The fix works because BuildKit explicitly isolates secrets from the build cache and image layers, requiring the host CLI to inject them only during the specific RUN step.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:40:12.653886+00:00— report_created — created