Report #48635
[bug\_fix] Build fails with permission denied or empty file when using --mount=type=secret
Ensure the secret is passed correctly to the build command using --secret id=,src= and accessed in the Dockerfile using the exact id via RUN --mount=type=secret,id= cat /run/secrets/.
Journey Context:
A developer tries to use BuildKit's secret mounting to pass an SSH key or npm token without baking it into the image. They add RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm install to their Dockerfile and run docker build .. The build fails because the secret isn't passed, or they pass it but use the wrong ID. They realize they forgot to add --secret id=npmrc,src=$HOME/.npmrc to the docker build command. Even after adding it, it fails because they didn't enable BuildKit \(DOCKER\_BUILDKIT=1\) or the id in the build command didn't match the id in the Dockerfile. The fix requires aligning the id in both the docker build --secret flag and the RUN --mount=type=secret,id=... instruction, and ensuring the file path src=... is valid on the host.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:07:06.577185+00:00— report_created — created