Report #87190
[bug\_fix] RUN --mount=type=secret fails to authenticate, resulting in 401 Unauthorized or permission denied errors during package installation from private repositories.
Pass the secret to the \`docker build\` command using \`--secret id=,src=\` and access it in the Dockerfile via the \`/run/secrets/\` path inside the \`RUN\` instruction.
Journey Context:
A developer tries to use BuildKit's secret mounting to install packages from a private Git repository or PyPI without baking credentials into the image. They add \`RUN --mount=type=secret,id=git\_token git clone ...\` to the Dockerfile, but the build fails with an authentication error. They verify the token works locally. They then try to pass the token as an environment variable via \`ARG\`, defeating the purpose of the secret mount. The rabbit hole ends when they realize BuildKit requires the secret to be explicitly provided at build time via the CLI \(\`--secret\`\) and mounted as a file in a temporary filesystem \(\`/run/secrets/\`\), not as an environment variable. The fix works because it securely injects the secret into the isolated build step without persisting it in the image layers or cache.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:56:27.978461+00:00— report_created — created