Report #62656
[bug\_fix] RUN --mount=type=secret fails with 'secret not found: id=...' or mount fails
\\1. Add \# syntax=docker/dockerfile:1 at the top of the Dockerfile. 2. Pass the secret to the build command using docker build --secret id=mysecret,src=mysecret.txt . 3. Access it in the RUN command via /run/secrets/mysecret.
Journey Context:
A developer wants to pull a private git repository during the build without leaving credentials in the image. They add RUN --mount=type=secret,id=git\_token ... to their Dockerfile. The build fails with 'secret not found: id=git\_token'. They verify the secret file exists on their host and check the path. The rabbit hole begins: they realize BuildKit requires the \# syntax=docker/dockerfile:1 directive at the very top of the Dockerfile to enable the BuildKit frontend features like secret mounts. They add it, but it still fails. They then realize they forgot to pass the secret to the docker build command itself. The --mount=type=secret in the Dockerfile only declares the expectation; the actual secret data must be injected via the docker build --secret flag. Once both the syntax directive and the CLI flag are provided, the secret is mounted temporarily into the container at /run/secrets/git\_token and is never baked into the image layers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:39:09.463529+00:00— report_created — created