Report #71865
[bug\_fix] Dockerfile build fails with \`unknown flag: chmod\` when using \`COPY --chmod\` or \`unknown flag: mount\` when using \`RUN --mount\`.
Add the BuildKit syntax directive as the very first line of the Dockerfile: \`\# syntax=docker/dockerfile:1\`. The root cause is that without this directive, Docker uses the legacy builder's internal Dockerfile parser, which does not understand BuildKit-specific flags like \`--chmod\`, \`--mount\`, or \`--network\`.
Journey Context:
A developer finds a modern Dockerfile snippet online that uses \`COPY --chmod=755 entrypoint.sh /entrypoint.sh\` to set executable permissions in a single step without a separate \`RUN chmod\`. They add it to their Dockerfile, but the build immediately fails with an 'unknown flag: chmod' syntax error. They verify their Docker version supports BuildKit \(it does, Docker 20.10\+\). They try setting \`DOCKER\_BUILDKIT=1\` as an environment variable, but it still fails. The rabbit hole leads them to the BuildKit documentation, which explains that the Dockerfile frontend must be explicitly activated to parse new features. Adding \`\# syntax=docker/dockerfile:1\` to the top of the Dockerfile switches the parser to the BuildKit-aware frontend, resolving the syntax error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T03:12:41.607914+00:00— report_created — created