Sub topic 10
Manifests, Configs, and the OCI Format
This chapter assumes you know that an image is a stack of layers and that layers are identified by content digests. It covers the metadata files that tie those layers into one image, and the open specification that defines them.
The three pieces of an image
An image is not one file. It is a small set of content-addressed objects, usually called blobs:
- Layer blobs are compressed tar archives of filesystem changes.
- A config blob is a JSON file that describes how to run the image and which layers it contains.
- A manifest is a JSON file that lists the config blob and the layer blobs by digest and size.
The manifest is the entry point. A registry resolves a tag to a manifest digest. The manifest points to the config and layers. Each of those is fetched by its own digest.
The manifest
This is a trimmed OCI image manifest. The digests are shortened here for readability. Real ones are sha256: followed by 64 hex characters.
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"config": {
"mediaType": "application/vnd.oci.image.config.v1+json",
"digest": "sha256:9c1e...",
"size": 1469
},
"layers": [
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:a41b...",
"size": 3398214
},
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:77d0...",
"size": 10452
}
]
}Each descriptor has three fields: a mediaType, a digest, and a size. A client checks the size and the digest of every blob it downloads. Layers are listed in order, base first. The manifest itself has a digest, which is the hash of its exact bytes. That value is what image@sha256:... refers to when you pin by digest.
The config
The config blob holds what the image is, as opposed to where its bytes are stored. A trimmed example:
{
"architecture": "amd64",
"os": "linux",
"config": {
"User": "65532",
"Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],
"Entrypoint": ["/app"],
"WorkingDir": "/"
},
"rootfs": {
"type": "layers",
"diff_ids": ["sha256:5f70...", "sha256:c2e8..."]
},
"history": [
{ "created_by": "COPY /out/app /app", "comment": "buildkit.dockerfile.v0" }
]
}configholds the runtime defaults that yourENTRYPOINT,CMD,ENV,USER,WORKDIR, andEXPOSEinstructions set.architectureandossay which platform the image runs on.rootfs.diff_idslists the digests of the layers after decompression.historyrecords one entry per build step. It is whatdocker historyprints.
Two digests describe each layer, and they differ. The manifest digest covers the compressed bytes that travel over the network. The diff_id covers the uncompressed tar. Compression settings can change the first without changing the second.
The image ID that Docker shows is the digest of the config blob. It is not the digest of the manifest. This is a frequent source of confusion:
| Value | What it hashes | Where you see it |
|---|---|---|
| Image ID | The config JSON | `docker images`, `docker image inspect --format '{{.Id}}'` |
| Manifest digest | The manifest JSON | `docker images --digests`, `RepoDigests`, `image@sha256:...` |
| Layer digest | The compressed layer | Manifest `layers[].digest` |
| `diff_id` | The uncompressed layer | Config `rootfs.diff_ids` |
The OCI format and Docker's older format
The Open Container Initiative (OCI) publishes two specifications that matter here. The Image Specification defines the manifest, config, and layer formats. The Distribution Specification defines the HTTP API that registries expose. Docker's original formats, the schema 2 manifests, came first. The OCI formats are nearly the same in structure but use different media types:
| Object | Docker media type | OCI media type |
|---|---|---|
| Manifest | `application/vnd.docker.distribution.manifest.v2+json` | `application/vnd.oci.image.manifest.v1+json` |
| Config | `application/vnd.docker.container.image.v1+json` | `application/vnd.oci.image.config.v1+json` |
| Layer | `application/vnd.docker.image.rootfs.diff.tar.gzip` | `application/vnd.oci.image.layer.v1.tar+gzip` |
| Multi-platform list | `application/vnd.docker.distribution.manifest.list.v2+json` | `application/vnd.oci.image.index.v1+json` |
Which format you get depends on the builder and the Docker version. Modern registries and runtimes such as containerd and Podman handle both. A manifest list or image index is a manifest that points to other manifests, one per platform. The multi-platform chapter covers it.
Inspecting a manifest on a registry
A registry serves manifests over HTTP, so you can read one with curl. This example uses the local registry from the earlier chapter. The Accept header tells the registry which formats you can read.
docker run -d -p 5000:5000 --name registry registry:2
docker tag myapp:1.0 localhost:5000/myapp:1.0
docker push localhost:5000/myapp:1.0
curl -s \
-H "Accept: application/vnd.oci.image.manifest.v1+json" \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
http://localhost:5000/v2/myapp/manifests/1.0Copy the config.digest from the output and fetch the config blob:
curl -s http://localhost:5000/v2/myapp/blobs/sha256:<config-digest>If you do not want to call the API by hand, docker buildx imagetools inspect --raw localhost:5000/myapp:1.0 prints the raw manifest. For a local image, docker save myapp:1.0 -o myapp.tar followed by tar -tf myapp.tar lists the same JSON files and layer blobs. The exact tar layout depends on your Docker version and image store.
Why this structure matters
Separating manifest, config, and layers gives you several behaviors you can rely on:
- Push skips existing data. Before uploading a layer, the client asks the registry whether that digest already exists. Layers shared with other images or earlier versions are not sent again.
- Registries can mount layers across repositories. If a blob exists in another repository on the same registry, a push can link it instead of uploading it.
- Tags are mutable pointers. Pushing
myapp:1.0again stores a new manifest and moves the tag. The old manifest still exists under its digest until cleanup removes it. - Verification is cheap. Because every object is named by its hash, a client can detect corruption or tampering of any blob it downloads.
- Rebuilds that change nothing produce the same layers. The manifest digest can still differ, because the config contains timestamps and history.
Common errors
manifest unknown. The tag or digest does not exist in that repository. Check the spelling, the repository path, and whether the push finished.- Mixing up image ID and digest.
docker pull image@sha256:<image-id>fails because the image ID is the config digest. Use the value fromRepoDigestsor--digests. unsupported media typeor a schema 1 response. The client did not send anAcceptheader for the format the registry stored. Add the headers shown above.- Different digests on different machines. A tag that points to a multi-platform index has one digest for the index and another for each platform manifest. Compare the same level on both sides.
- Expecting
docker historyto match the manifest. History comes from the config, not from the layer list. Some history entries, such asENVorENTRYPOINT, create no layer.
Exercise
You run docker image inspect --format '{{.Id}}' myapp:1.0 and get sha256:9c1e.... A teammate tries docker pull registry.example.com/team/myapp@sha256:9c1e... and gets manifest unknown. Why does it fail, and which value should they use?
Show answer
The image ID is the digest of the config blob, but a pull by digest needs the manifest digest. The registry has no manifest with that hash, so it reports manifest unknown. The teammate should use the manifest digest from docker images --digests, from the RepoDigests field of docker image inspect, or from the output of docker buildx imagetools inspect after the image has been pushed.
Exercise
A manifest lists two layers. The config's history has five entries. Is that a contradiction?
Show answer
No. History records every build step, but only steps that change the filesystem produce a layer. Instructions such as ENV, ENTRYPOINT, WORKDIR, and EXPOSE only change the config, so they appear in history without adding an entry to the manifest's layers list.