Report #25198
[bug\_fix] RUN --mount=type=secret,id=mysecret fails with 'secret not found: mysecret' or the secret file is empty inside the RUN command.
Pass the secret to the docker build command using \`--secret id=mysecret,src=\`, and ensure the environment supports BuildKit \(either via \`DOCKER\_BUILDKIT=1\` or \`docker buildx build\`\).
Journey Context:
A developer wants to clone a private git repo or pull from a private package registry during the build without leaving credentials in the image layers. They add \`RUN --mount=type=secret,id=ssh,target=/root/.ssh/id\_rsa ...\` to their Dockerfile. The build fails with 'secret not found'. They check their local \`~/.ssh/id\_rsa\` and it exists. They fall down a rabbit hole checking file permissions and SSH configs. They eventually realize that the Dockerfile merely \*declares\* the requirement for a secret; it does not automatically pull files from the host. The BuildKit client must explicitly mount the secret at build time. Running \`docker build --secret id=ssh,src=~/.ssh/id\_rsa .\` passes the host file into the BuildKit sandbox for the duration of that specific \`RUN\` instruction only. This works because BuildKit enforces a strict separation between the build environment and the host, requiring explicit, scoped consent to access sensitive data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:41:55.772305+00:00— report_created — created