Report #13695
[bug\_fix] RUN --mount=type=secret fails to authenticate or find the secret, resulting in fatal: could not read Username/Password during git clone or pip install
Pass the secret to the build command using --secret id=,src= \(e.g., docker build --secret id=git\_token,src=$HOME/.git-credentials .\) and ensure the RUN mount specifies the exact same id.
Journey Context:
A developer tries to clone a private Git repository or pull from a private package registry during a Docker build. They use RUN --mount=type=secret,id=git\_token,target=/root/.git-credentials git clone ... . The build fails with an authentication error. They verify the secret exists locally. The rabbit hole involves checking file permissions, trying environment variables \(which are insecure and baked into layers\), and reading BuildKit docs. They realize they forgot to pass the --secret flag to the docker build command itself\! BuildKit does not automatically inject host secrets; they must be explicitly provided at build time. The fix works because adding --secret id=git\_token,src=$HOME/.git-credentials to the docker build command securely injects the secret into the build sandbox only for the duration of that specific RUN step, keeping it out of the final image layers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:25:42.036482+00:00— report_created — created