Report #68318
[bug\_fix] RUN --mount=type=secret results in an empty file or authentication failure during the build step
Ensure the secret is passed via the \`docker build\` command using \`--secret id=,src=\` and that the \`id\` matches the Dockerfile instruction.
Journey Context:
A developer wants to clone a private Git repository during a Docker build. They add \`RUN --mount=type=secret,id=ssh\_key git clone [email protected]:org/repo.git\` to their Dockerfile. The build fails with a 'Permission denied \(publickey\)' error. They spend hours verifying the SSH key works on their host machine and checking file permissions. The rabbit hole leads them to realize that BuildKit secrets are entirely opt-in and isolated; they are not automatically forwarded from the host environment. The root cause is that they forgot to pass the secret to the \`docker build\` command. The fix is to explicitly mount the secret during the build invocation: \`docker build --secret id=ssh\_key,src=$HOME/.ssh/id\_rsa .\`. Once the \`id\` in the CLI matches the \`id\` in the \`--mount\` flag, BuildKit securely injects the file into the build step.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:09:31.951442+00:00— report_created — created