Sub topic 10
Manifests, Configs, and the OCI Format
This chapter assumes you know what layers and digests are from earlier chapters. You should also be comfortable reading JSON on the command line.
The three parts of an image
An image is stored as three kinds of objects. Each one is identified by its digest.
- Layers are compressed tar archives of filesystem changes.
- The config is a JSON document. It holds the settings used to run the image: environment variables, entrypoint, command, working directory and exposed ports. It also holds the image history and the list of uncompressed layer digests, called
diff_ids. - The manifest is a JSON document that lists the config's digest and the digest, size and media type of each layer.
The manifest is the entry point. When you pull myapp:1.0, the registry resolves the tag to a manifest digest. The client downloads the manifest, then the config, then any layers it doesn't already have.
Looking at the pieces
You can print the manifest of an image in a registry exactly as stored:
docker buildx imagetools inspect --raw alpine:3.20For a multi-platform image, this prints an image index. That is a manifest that lists other manifests, one per platform (covered in a later chapter). To see the layer digests recorded in a local image's config, run:
docker image inspect --format '{{json .RootFS.Layers}}' alpine:3.20These are diff_ids, digests of the uncompressed layers. They differ from the digests in the manifest, which cover the compressed layers. This is why the same layer can show two different digests depending on where you look.
Why the image ID is the config digest
The image ID that docker image inspect --format '{{.Id}}' prints is the digest of the config. The manifest digest is a separate value. It is the one you use to pin an image in a registry. Changing the compression or the registry's manifest format changes the manifest digest. The config digest stays the same.
The OCI format
The Open Container Initiative (OCI) publishes the image specification that these documents follow. Docker's older manifest format was Docker Image Manifest V2, Schema 2. The OCI format is nearly identical but uses different media types, such as application/vnd.oci.image.manifest.v1+json. Most registries and runtimes, including containerd and Podman, accept both. An image built by one tool can usually be pulled by another.
| Object | Media type (OCI) | Identified by |
|---|---|---|
| Manifest | `application/vnd.oci.image.manifest.v1+json` | Manifest digest |
| Config | `application/vnd.oci.image.config.v1+json` | Config digest (image ID) |
| Layer | `application/vnd.oci.image.layer.v1.tar+gzip` | Compressed layer digest |
Common errors
- Confusing the two digests.
docker pull name@sha256:...needs the manifest digest, not the image ID. - Expecting digests to survive a rebuild. A rebuild can change timestamps and metadata. That changes the config and therefore the manifest, even if your code is the same.
- Assuming a tag is one image. A tag can point at an image index, which resolves to different manifests per platform.
Exercise
You run docker image inspect --format '{{.Id}}' myapp:1.0 and try docker pull registry.example.com/team/myapp@sha256:<that value>. The pull fails. Why?
Show answer
The image ID is the digest of the image config, but a pull by digest needs the digest of the manifest in the registry. Use the digest shown by docker buildx imagetools inspect or docker images --digests instead.