Report #55501
[bug\_fix] RUN --mount=type=secret fails or secret file is empty during build
Ensure BuildKit is explicitly enabled \(set \`DOCKER\_BUILDKIT=1\` or use \`docker buildx build\`\). Pass the secret to the build command using \`--secret id=mysecret,src=./secret.txt\` and access it in the Dockerfile via \`RUN --mount=type=secret,id=mysecret,target=/secret.txt cat /secret.txt\`.
Journey Context:
A developer tries to securely pass a GitHub PAT to a Dockerfile to clone a private repo using \`RUN --mount=type=secret,id=gh\_token git clone ...\`. The git clone fails with an authentication error. They echo the secret file path inside the RUN step and find it empty. They go down a rabbit hole checking file permissions and environment variables, only to realize they forgot to pass the \`--secret\` flag to the \`docker build\` command itself. Furthermore, they were using the legacy \`docker build\` command without \`DOCKER\_BUILDKIT=1\`, so the \`--mount\` syntax was silently failing or not parsed as a BuildKit instruction. The fix requires both enabling BuildKit and explicitly piping the secret from the host into the build via the CLI flag.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:39:11.855978+00:00— report_created — created