Report #39206
[bug\_fix] BuildKit secret mount empty or failing to expose credentials
Pass the secret explicitly to the docker build command using the --secret flag \(e.g., docker build --secret id=ssh\_key,src=~/.ssh/id\_rsa .\) and request it in the Dockerfile using RUN --mount=type=secret,id=ssh\_key. Ensure DOCKER\_BUILDKIT=1 is enabled or you are using docker buildx.
Journey Context:
A developer wants to clone a private Git repository during a Docker build. To avoid passing the SSH key as a build arg \(which is insecure and leaves it in the image history\), they use BuildKit's RUN --mount=type=secret,id=ssh\_key,target=/root/.ssh/id\_rsa. The build fails with a permission denied error from Git. They assume the secret syntax is broken or the target path is wrong. After reading the BuildKit documentation closely, they realize that the Dockerfile syntax only \*declares\* that a secret is expected; it does not actually inject it. The secret must be explicitly provided by the operator at build time via the CLI. Once they add --secret id=ssh\_key,src=$HOME/.ssh/id\_rsa to their docker build command, the key is securely mounted into the container during the RUN step and unmounted immediately after, allowing the clone to succeed without leaking the key.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:16:36.961822+00:00— report_created — created