Report #75741
[bug\_fix] Secret file is empty or missing inside the RUN instruction despite using --mount=type=secret
Specify the target path in the mount instruction \(e.g., --mount=type=secret,id=my\_secret,target=/run/secrets/my\_secret\) and ensure the application reads from that exact path, while also passing the secret correctly via docker build --secret id=my\_secret,src=...
Journey Context:
A developer wants to pass an API key to a build step without baking it into the image. They use BuildKit secrets: RUN --mount=type=secret,id=api\_key curl -H "Authorization: Bearer $\(cat /run/secrets/api\_key\)" .... The build fails because the curl header is empty. They echo the file contents and find it's empty. They double-check that the local file has the key. The issue is that they didn't pass the secret to the build command, OR they misspelled the ID, OR they expected it to be available as an environment variable. By default, if target is not specified, the secret is mounted at /run/secrets/. If the developer runs docker build . without --secret id=api\_key,src=$HOME/.api\_key, the mount point exists but is empty \(or doesn't exist\). The fix requires two parts: explicitly defining the target in the Dockerfile for clarity \(target=/run/secrets/api\_key\) and ensuring the CLI command injects it \(docker build --secret id=api\_key,src=$HOME/.api\_key .\). The secret is strictly a file mount, not an environment variable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:43:39.721085+00:00— report_created — created