Dockerfile
The Dockerfile reference from the Moby BuildKit project, the text that docs.docker.com publishes as its Dockerfile reference, read from the BuildKit repository at its latest release. It covers the format, parser directives, shell and exec form, and every instruction.
Follow the workflow below step by step. Every rule here comes from a source in Sources. Quoted requirements are sentences taken from the pinned text, labelled with the section they come from. When a rule and the pinned source disagree, the source wins; when the source has a newer revision than the pin, follow the refresh steps.
Inputs (fill in, or ask before starting)
- Role: Dockerfile author or reviewer, or a tool that parses or lints Dockerfiles.
- Target version: Dockerfile (current). See
references/versions.md.
- Revision: the pinned revision in Sources, unless the user names another.
- Sources: when refreshing this skill, re-read every URL in Sources and check the publisher for a newer revision or version line.
Invariants
- Parser directives. "Therefore, all parser directives must be at the top of a Dockerfile."
- Shell and exec form, Exec form. "The exec form is parsed as a JSON array, which means that you must use double-quotes (") around words, not single-quotes (')."
- FROM. "As such, a valid Dockerfile must start with a
FROM instruction."
- FROM. "
ARG is the only instruction that may precede FROM in the Dockerfile."
- RUN --mount=type=secret. "This mount type allows the build container to access secret values, such as tokens or private keys, without baking them into the image."
- CMD. "There can only be one
CMD instruction in a Dockerfile. If you list more than one CMD, only the last one takes effect."
- ENV. "The environment variables set using
ENV will persist when a container is run from the resulting image."
- Understand how CMD and ENTRYPOINT interact. "Dockerfile should specify at least one of
CMD or ENTRYPOINT commands."
- WORKDIR. "Therefore, to avoid unintended operations in unknown directories, it's best practice to set your
WORKDIR explicitly."
- ARG, Scope. "To use an argument in multiple distinct stages, each stage must include the
ARG instruction, or they must both be based on a shared base stage in the same Dockerfile where the variable is declared."
- HEALTHCHECK. "There can only be one
HEALTHCHECK instruction in a Dockerfile. If you list more than one then only the last HEALTHCHECK will take effect."
Workflow
- Pick the version. Use the current line unless a named consumer needs a supported one. Do not author a legacy line. Emit a preview only when its posture is build and the user asked for that draft.
->
references/versions.md
✓ The target version is recorded, and it is not a legacy line.
- Apply the pinned requirements. Walk the quotes in
references/requirements.md and implement each one that applies to the role.
-> references/requirements.md
✓ Each applicable quote is either implemented or recorded as out of scope for the role, with the section it came from.
- Upgrade (only when asked). Follow the upgrade section from the source line to the target.
->
references/versions.md
✓ The result cites the target line and no longer depends on a requirement that only the old line stated.
Verify before done
Reference index
references/versions.md: every version line, which one to use, and how to upgrade. Load for steps 1 and 3.
references/requirements.md: quotes taken from the pinned specification, grouped by source. Load for step 2.
Related skills
Install related spec skills by name with npx skills add ScaleDockHQ/scaledock-skills --skill <name>: oci, compose-spec, buildpacks.
Sources
Status uses the publishing body's own maturity term. Checked is the date the source was last read.
- Dockerfile reference: Reference, BuildKit v0.33.1 (commit 8c91502), Dockerfile syntax docker/dockerfile:1, checked 2026-10-06.
1---2name: dockerfile3description: >-4 Dockerfile: write and review Dockerfile build instructions for container images. Covers Dockerfile. Use when writing a Dockerfile. Triggers: Dockerfile.5license: MIT6metadata:7 source: https://skillmd.com/skills/scaledockhq/dockerfile8 author: ScaleDockHQ9 version: "1.1.0"10 kind: standard11---1213# Dockerfile1415The Dockerfile reference from the Moby BuildKit project, the text that docs.docker.com publishes as its Dockerfile reference, read from the BuildKit repository at its latest release. It covers the format, parser directives, shell and exec form, and every instruction.1617**Follow the workflow below step by step.** Every rule here comes from a source in [Sources](#sources). Quoted requirements are sentences taken from the pinned text, labelled with the section they come from. When a rule and the pinned source disagree, the source wins; when the source has a newer revision than the pin, follow the refresh steps.1819## Inputs (fill in, or ask before starting)2021- Role: Dockerfile author or reviewer, or a tool that parses or lints Dockerfiles.22- Target version: Dockerfile (current). See [`references/versions.md`](references/versions.md).23- Revision: the pinned revision in [Sources](#sources), unless the user names another.24- Sources: when refreshing this skill, re-read every URL in [Sources](#sources) and check the publisher for a newer revision or version line.2526## Invariants27281. **Parser directives.** "Therefore, all parser directives must be at the top of a Dockerfile."292. **Shell and exec form, Exec form.** "The exec form is parsed as a JSON array, which means that you must use double-quotes (") around words, not single-quotes (')."303. **FROM.** "As such, a valid Dockerfile must start with a `FROM` instruction."314. **FROM.** "`ARG` is the only instruction that may precede `FROM` in the Dockerfile."325. **RUN --mount=type=secret.** "This mount type allows the build container to access secret values, such as tokens or private keys, without baking them into the image."336. **CMD.** "There can only be one `CMD` instruction in a Dockerfile. If you list more than one `CMD`, only the last one takes effect."347. **ENV.** "The environment variables set using `ENV` will persist when a container is run from the resulting image."358. **Understand how CMD and ENTRYPOINT interact.** "Dockerfile should specify at least one of `CMD` or `ENTRYPOINT` commands."369. **WORKDIR.** "Therefore, to avoid unintended operations in unknown directories, it's best practice to set your `WORKDIR` explicitly."3710. **ARG, Scope.** "To use an argument in multiple distinct stages, each stage must include the `ARG` instruction, or they must both be based on a shared base stage in the same Dockerfile where the variable is declared."3811. **HEALTHCHECK.** "There can only be one `HEALTHCHECK` instruction in a Dockerfile. If you list more than one then only the last `HEALTHCHECK` will take effect."3940## Workflow41421. **Pick the version.** Use the current line unless a named consumer needs a supported one. Do not author a legacy line. Emit a preview only when its posture is build and the user asked for that draft.43 -> [`references/versions.md`](references/versions.md)44 ✓ The target version is recorded, and it is not a legacy line.452. **Apply the pinned requirements.** Walk the quotes in [`references/requirements.md`](references/requirements.md) and implement each one that applies to the role.46 -> [`references/requirements.md`](references/requirements.md)47 ✓ Each applicable quote is either implemented or recorded as out of scope for the role, with the section it came from.483. **Upgrade** (only when asked). Follow the upgrade section from the source line to the target.49 -> [`references/versions.md`](references/versions.md)50 ✓ The result cites the target line and no longer depends on a requirement that only the old line stated.5152## Verify before done5354- [ ] The artifact cites the target line's revision from [Sources](#sources).55- [ ] Every applicable quoted requirement in [`references/requirements.md`](references/requirements.md) holds.56- [ ] Secrets reach the build through `RUN --mount=type=secret`, not through `ENV`, whose values persist when a container is run from the image.57- [ ] Nothing from a preview line is emitted unless its posture is build and the user opted in.5859## Reference index6061- **`references/versions.md`**: every version line, which one to use, and how to upgrade. Load for steps 1 and 3.62- **`references/requirements.md`**: quotes taken from the pinned specification, grouped by source. Load for step 2.6364## Related skills6566Install related spec skills by name with `npx skills add ScaleDockHQ/scaledock-skills --skill <name>`: `oci`, `compose-spec`, `buildpacks`.6768## Sources6970Status uses the publishing body's own maturity term. Checked is the date the source was last read.7172- [Dockerfile reference](https://raw.githubusercontent.com/moby/buildkit/8c91502cf280bd70a0c50912ce251c46a8881d9f/frontend/dockerfile/docs/reference.md): Reference, BuildKit v0.33.1 (commit 8c91502), Dockerfile syntax docker/dockerfile:1, checked 2026-10-06.