Sub topic 10
Pinning the frontend by tag or digest for reproducible builds
This chapter assumes you can write a basic Dockerfile, run docker build, and already know that the syntax directive on the first line selects the Dockerfile frontend. Here you will learn how much control the tag in that directive gives you, and when to pin it more tightly.
What the syntax directive actually pulls
The syntax directive names a container image. BuildKit pulls that image and uses it to parse your Dockerfile. The image is the frontend. Because the frontend is an image, it has tags and digests like any other image, and the one you choose decides which Dockerfile features and build checks are available.
# syntax=docker/dockerfile:1
FROM alpine:3.20
RUN echo "frontend selected by tag"The tag 1 is a floating tag. It always points to the newest release in the 1.x line. This is the form most people should start with. You receive bug fixes and new features, such as heredoc improvements and new check rules, without editing the Dockerfile.
The cost of a floating tag
A floating tag means two builds of the same Dockerfile can parse it with different frontend versions. That causes several problems:
- A new release can add a check rule that produces warnings that were not there last week.
- With
# check=error=true, those new warnings can turn a passing build into a failing one. - A rebuild of an old commit may not match the original build.
If these risks matter to you, pin the frontend to something that does not move.
Pinning options
You can choose how tightly to pin. The three levels below go from loosest to strictest.
| Directive | What it selects | Moves over time? |
|---|---|---|
| `docker/dockerfile:1` | Latest 1.x release | Yes |
| `docker/dockerfile:1.10` | Latest patch of 1.10 | Yes, patches only |
| `docker/dockerfile:1.10.0` | Exact release | The tag could be re-pushed, but this is rare |
| `docker/dockerfile:1.10.0@sha256:...` | Exact image content | No |
A tag such as 1.10.0 is readable, but a tag is a label that a registry owner can repoint. A digest is a hash of the image content, so it cannot change without changing the digest itself. Adding a digest gives you a pin that is verifiable.
# syntax=docker/dockerfile:1.10.0@sha256:<digest-of-that-release>
FROM alpine:3.20
RUN echo "frontend pinned by tag and digest"Replace the placeholder with the real digest of the release you want. Do not copy a digest from a document you cannot verify. When both a tag and a digest are present, BuildKit resolves by the digest, and the tag is kept so a reader can see which version it is.
Finding the digest
You can read the digest from the registry with Docker's image tooling:
docker buildx imagetools inspect docker/dockerfile:1.10.0The output includes a Digest: line. Copy that value into the directive after the @.
How the choice flows through a build
Choosing a level
Match the pin to how much surprise you can accept.
- For learning and local work, use
docker/dockerfile:1. You get current features with no upkeep. - For team projects, consider a minor version such as
1.10. Behavior changes less often. - For builds that must be reproducible, such as release pipelines, use an exact tag with a digest.
Pinning has an upkeep cost. You must update the directive on purpose to get new features and checks. Many teams let a dependency update tool propose these changes as pull requests, so the update is reviewed rather than silent.
Exercise
Your release pipeline runs with # check=error=true, and last week a build that had passed started failing with no change to the Dockerfile. The directive reads # syntax=docker/dockerfile:1. What is the likely cause, and how do you prevent it?
Show answer
The floating tag 1 moved to a newer frontend release that added a check rule, which now produces a warning that error=true turns into a failure. Pin the frontend to an exact tag plus digest, for example docker/dockerfile:1.10.0@sha256:<digest>, and update it deliberately, fixing or skipping new rules when you do.