Report #2832
[bug\_fix] Private package manager or git clone fails during docker build despite using RUN --mount=type=secret
Use the \`docker build --secret id=,src=\` flag to pass the secret to the build, and mount it in the Dockerfile using \`RUN --mount=type=secret,id= \`. Ensure the command inside the \`RUN\` instruction actually reads from the mounted file path \(available at \`/run/secrets/\`\), rather than expecting an environment variable.
Journey Context:
A developer needs to pull a private npm package or git repo during a \`docker build\`. They try using build args \(\`--build-arg GIT\_TOKEN=...\`\), but realize this exposes the token in the image history. They switch to BuildKit secrets: \`RUN --mount=type=secret,id=git\_token git clone https://user:$\(cat /run/secrets/git\_token\)@github.com/repo.git\`. The build fails with authentication errors. They debug by echoing the secret \(carefully\) and realize it's empty. The issue is they forgot to pass the secret to the \`docker build\` command itself\! BuildKit requires the secret to be explicitly forwarded via the CLI: \`docker build --secret id=git\_token,src=$HOME/.git-token .\`. Without the CLI flag, the \`--mount=type=secret\` in the Dockerfile mounts an empty directory. Once the CLI flag is added, the secret is securely mounted into the build container at \`/run/secrets/git\_token\` and the command succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T14:19:58.471586+00:00— report_created — created