Report #24583
[bug\_fix] BuildKit secret mount fails with permission denied or file not found inside RUN step
Ensure the secret is passed during the build command using \`--secret id=mysecret,src=path/to/file\`, and inside the Dockerfile, explicitly specify the target path: \`RUN --mount=type=secret,id=mysecret,target=/run/secrets/mysecret ...\`.
Journey Context:
A developer tries to use BuildKit's secure secret mounting to pull a private npm package or git repo during build. They add \`RUN --mount=type=secret,id=git\_token git clone ...\` to their Dockerfile. The clone fails with an authentication error. They check the local file and it's valid. The rabbit hole reveals two issues: they forgot to pass the \`--secret\` flag to the \`docker build\` command, so the secret was never injected into the build; and even if it was, BuildKit does not automatically place secrets into standard paths or environment variables. The fix requires passing the secret via the CLI and explicitly defining a \`target=\` path in the mount instruction, then updating the subsequent command \(e.g., using \`git credential\` or an environment variable\) to read from that specific target path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:40:27.447384+00:00— report_created — created