Sub topic 4
Digests: how content is addressed
This chapter assumes you can build, tag, and push images, and that you know a registry stores images under repository names and tags. It explains how digests identify image content. The image index chapter that follows relies on this.
What a digest is
A digest is a hash of some content, written as an algorithm name, a colon, and a hex string. In practice the algorithm is almost always SHA-256.
sha256:3b1f0c9a5d7e2f84a6c1b0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9The registry stores content under its digest. This is called content-addressable storage. If two blobs have the same bytes, they have the same digest. If one byte differs, the digest differs completely.
What gets a digest
Several objects in an image have their own digest:
| Object | What the digest covers |
|---|---|
| Layer blob | The compressed layer archive |
| Config blob | The JSON with environment, entrypoint, and layer history |
| Image manifest | The manifest JSON that lists the config and layers |
| Image index | The index JSON that lists per-platform manifests |
A manifest refers to its config and layers by digest. An index refers to its manifests by digest. Each level therefore contains the hashes of the level below it.
Changing any layer changes its digest. That changes the manifest that lists it, which changes the index that lists the manifest. A change anywhere below produces a new digest at the top.
Tags versus digests
A tag is a mutable name. A digest is an immutable identifier. Someone can push a new image to app:1.0 tomorrow, and the tag will then point to different content. A reference by digest always resolves to the same bytes.
docker pull alpine:3.20
docker pull alpine@sha256:<digest-from-your-pull-output>Docker prints the digest after a pull (Digest: sha256:...). You can also see it with docker buildx imagetools inspect, which a later chapter covers.
Which digest do you have?
For a multi-platform tag, the digest you see usually belongs to the index. Pulling by that digest returns the index, and the client then picks a manifest for its platform. Pulling by a per-platform manifest digest skips that choice and always gives you that one platform.
This matters when you pin images:
- Pinning to the index digest keeps the set of platforms fixed and still works on both amd64 and arm64 hosts.
- Pinning to a manifest digest locks you to one architecture, so the same reference fails or runs the wrong image on other CPUs.
Common errors
- Copying a digest from
docker images --digestsand assuming it is the same as the registry's index digest. A locally stored image may show a manifest digest for the platform you pulled. - Expecting a rebuild to keep the same digest. Timestamps and layer metadata often change the hash, even when the source code is the same.
- Pinning a manifest digest in a Dockerfile
FROMline, then building on a different architecture.
Exercise
You pin FROM registry.example.com/team/app@sha256:X where X is the digest of the amd64 manifest. A teammate on an arm64 laptop builds the image. What is the likely problem, and which digest should you have pinned for both platforms?
Show answer
The reference points to a single-platform manifest, so the arm64 build gets amd64 content or fails to match the requested platform. Pin the digest of the image index instead. The client then selects the manifest that matches each host.