Sub topic 7
Tags versus digests
This chapter assumes you can write a Dockerfile, run docker build and docker push, and read a GitHub Actions workflow. It explains the two ways to name an image, and why CI should record both.
What a tag is
A tag is a human-readable label attached to an image in a repository, such as ghcr.io/example-org/example-app:1.4.0. A tag is mutable. The registry lets you point the same tag at a different image at any time. Pushing :latest twice leaves :latest pointing at the second image only.
If you leave the tag off, Docker assumes :latest. That tag has no special meaning to the registry. It is only a default name.
What a digest is
A digest is a content hash of the image manifest. It looks like sha256:3b5c... and is computed from the manifest's bytes. A digest is immutable. If the content changes, the digest changes. You reference an image by digest with @:
ghcr.io/example-org/example-app@sha256:3b5c0f...For a multi-platform image, the digest of the tag identifies the manifest list (also called an image index). That index points to one manifest per platform, and each of those has its own digest.
Seeing both in practice
The imagetools command prints the digest for a published tag and lists the platforms behind it.
docker buildx imagetools inspect ghcr.io/example-org/example-app:latestLook for the Name:, MediaType: and Digest: lines at the top. The Digest: value is what you can pin to.
Comparing them
| Property | Tag | Digest |
|---|---|---|
| Can change over time | Yes | No |
| Readable | Yes | No |
| Several per image | Yes | One per manifest |
| Good for | Humans, discovery, "latest of this line" | Reproducibility, audit, deployment pinning |
Where each belongs in a CI pipeline
Use tags to communicate intent. A release tag such as 1.4.0 tells people which version they are pulling. A commit tag such as sha-a1b2c3 ties an image to the source commit that produced it.
Use digests when you need certainty. Two pulls of :1.4.0 a week apart can return different images if someone re-pushed the tag. A deployment that references the digest cannot.
The docker/build-push-action step exposes the digest it pushed as the output digest. Give the step an id and you can read it in later steps:
- name: Build and push
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/example-org/example-app:latest
- name: Record the digest
run: echo "Pushed ${{ steps.push.outputs.digest }}" >> "$GITHUB_STEP_SUMMARY"Write the digest to the job summary, a release note or a deployment manifest. Then you can always say exactly which bytes shipped.
Common mistakes
- Deploying
:latestto production. You cannot tell which build is running, and a rollback has nothing stable to return to. - Assuming a version tag is frozen. Registries allow overwrites unless you enable tag immutability, which some registries offer as a setting. GitHub Container Registry does not enforce it, so treat the rule as a team convention.
- Copying a platform-specific digest when you meant the manifest list digest. Pinning to one platform's digest breaks pulls on other architectures.
- Reading the digest from a local
docker buildand expecting it to match the registry's. The registry digest only exists after the push.
Later chapters cover how to generate tags automatically and how to promote an image by digest.
Exercise
Your deployment file says ghcr.io/example-org/example-app:1.4.0. A teammate re-pushes 1.4.0 after a hotfix, and production now runs different code than staging tested. What change to the deployment file prevents this, and where in the workflow do you get the value?
Show answer
Reference the image by digest, for example ghcr.io/example-org/example-app@sha256:<digest>. Get the digest from the digest output of docker/build-push-action (read it as steps.<id>.outputs.digest after giving the step an id), or from docker buildx imagetools inspect.
Exercise
Why is a digest copied from a local docker build not a reliable way to reference an image that you later push?
Show answer
The registry digest is computed from the manifest stored in the registry, and it is only known after the push. Use the digest reported by the push step or by imagetools inspect on the published tag.