Report #12248
[bug\_fix] \`RUN --mount=type=secret,id=gitcreds\` fails to access the secret, or the secret is inadvertently baked into the final image layer.
Ensure the secret is passed via the build command \(\`docker build --secret id=gitcreds,src=$HOME/.gitconfig .\`\) and accessed inside the \`RUN\` step via the standard \`/run/secrets/\` path. Never use \`ARG\` or \`ENV\` for secrets.
Journey Context:
A developer needs to clone a private git repository during a Docker build. They try passing a Personal Access Token via \`ARG\`, which works but leaves the token exposed in the image history \(\`docker history\`\). They switch to \`RUN --mount=type=secret,id=gitcreds\` but the clone step fails with authentication errors. They spend hours debugging git credentials and SSH keys inside the container. The root cause is forgetting to pass the \`--secret\` flag to the \`docker build\` command itself, or trying to \`cat\` a file path that doesn't exist because the secret mount wasn't configured. The fix works because BuildKit securely injects the secret into the \`/run/secrets/\` directory only for the duration of that specific \`RUN\` step, keeping it completely out of the build cache and the final image layers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:24:27.271887+00:00— report_created — created