Report #78667
[bug\_fix] Private package repository authentication fails \(e.g., 401 Unauthorized or fatal: could not read Username for 'https://github.com'\) during RUN --mount=type=secret despite the Dockerfile being configured
Pass the secret to the \`docker build\` command using the \`--secret\` flag \(e.g., \`docker build --secret id=gitcreds,src=$HOME/.git-credentials .\`\). BuildKit does not automatically inject host secrets into the build.
Journey Context:
A developer wants to clone a private GitHub repository inside a Dockerfile without hardcoding credentials. They add \`RUN --mount=type=secret,id=gitcreds,target=/root/.git-credentials git clone ...\`. The build fails with a git authentication prompt or a 401 error. The developer spends hours verifying the credential file exists on the host, checking its format, and adjusting the target path. They eventually realize that while the Dockerfile \*declares\* the mount, the Docker CLI must be explicitly told to forward the secret from the host. Without the \`--secret id=gitcreds,src=...\` flag in the \`docker build\` command, BuildKit simply mounts an empty directory or skips the secret entirely, leaving git unauthenticated. Adding the CLI flag securely passes the secret into the build step.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:38:07.174744+00:00— report_created — created