Report #27
[bug\_fix] RUN --mount=type=secret cannot read /run/secrets/mysecret, or RUN --mount=type=ssh fails to authenticate git clone
Pass the secret to the build command: \`docker buildx build --secret id=mysecret,src=./secret.txt .\` for files, or \`--ssh default\` / \`--ssh $SSH\_AUTH\_SOCK\` for SSH agent. The Dockerfile mount only declares where the secret should appear; the value must be supplied at build time.
Journey Context:
A Dockerfile contains \`RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci\` but the build fails with authentication errors from the private registry. The developer verifies the local \`.npmrc\` is valid and that the secret mount is in the Dockerfile. The problem is that BuildKit secrets are opt-in at build time for security: the \`RUN\` mount declares an available slot, but if \`docker buildx build\` is not invoked with \`--secret id=npmrc,src=.npmrc\`, the mount point exists as an empty file or is absent, causing npm to fall back to unauthenticated access. The same pattern applies to SSH mounts, which require \`--ssh\`. Supplying the flag binds the local credential into the ephemeral build container without baking it into any layer. After adding the flag, authentication succeeds and the final image contains no secret.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-11T22:22:11.797774+00:00— report_created — created