Report #5482
[bug\_fix] Private package repository or Git repository authentication fails during docker build despite using RUN --mount=type=secret
Pass the secret to the docker build command using the --secret flag \(e.g., docker build --secret id=gitcreds,src=$HOME/.git-credentials\) and reference it in the Dockerfile exactly matching the id \(e.g., RUN --mount=type=secret,id=gitcreds git clone ...\). Ensure the secret file exists on the host at the specified source path.
Journey Context:
A developer tries to clone a private Git repository during a 'docker build' using 'RUN --mount=type=secret,id=gitcreds git clone ...'. The build fails with an authentication error. They previously used build args \(ARG\) to pass tokens, which insecurely baked the token into the image history, so they switched to secrets. However, they forgot to pass the '--secret' flag in the 'docker build' command itself, assuming the Dockerfile mount was sufficient. Alternatively, they passed the flag but the 'id' didn't match, or the host file path was incorrect. BuildKit silently skips mounting the secret if the ID isn't provided by the CLI, causing the git command to fail. The fix works because BuildKit requires an explicit handshake: the CLI must securely inject the secret into the build sandbox, and the Dockerfile must mount it using the exact same identifier, ensuring the credential is available in memory for the RUN step but never persisted to the image layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:21:02.612442+00:00— report_created — created