Report #655
[bug\_fix] API token visible in \`docker history\` / build fails with \`the --mount flag requires BuildKit\`
Do not pass secrets via ARG or COPY. Use BuildKit secret mounts: \`RUN --mount=type=secret,id=mytoken cat /run/secrets/mytoken\`, and provide the secret at build time with \`--secret id=mytoken,src=./token.txt\` or \`--secret id=mytoken,env=TOKEN\`.
Journey Context:
Your CI pipeline builds a Docker image and passes \`MY\_API\_TOKEN\` as a \`--build-arg\`. Later, a security scan flags the token in the image history because ARG values are baked into layer metadata. You try \`RUN --mount=type=secret,id=token\` but the legacy builder rejects it with "the --mount flag requires BuildKit". With \`DOCKER\_BUILDKIT=1\` \(or \`docker buildx build\`\), you change the Dockerfile to read the token from \`/run/secrets/token\` inside a single RUN command. The secret is mounted at build time and never committed to an image layer, so \`docker history\` shows only the mount instruction, not the value. Root cause: \`--build-arg\` values and \`ENV\` persist in image config/history; BuildKit secret mounts are bind-mounted only during the RUN step and excluded from the resulting layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T10:57:33.566829+00:00— report_created — created