Sub topic 1
What an ECR Registry Stores: Images, Layers, and Manifests
Prerequisites
This chapter assumes you can build and run a container with Docker and read a Dockerfile. It also assumes you have the AWS CLI installed with working credentials and a basic idea of what an IAM user or role is. You don't need an ECR repository yet. Later chapters create one, but this chapter explains what ECR holds once you push to it.
Why the storage model matters
Amazon Elastic Container Registry (ECR) is a managed service for storing container images. You will meet digests, media types, and "layer already exists" messages in nearly every ECR task. Tag immutability, lifecycle policies, scanning, and replication all act on the objects described here. If you know what ECR stores, those features are easier to reason about.
Images are a manifest plus blobs
A container image is not one file. It is a set of content-addressed objects:
- Layers. Each layer is a compressed tar archive (a "blob") holding filesystem changes. Most Dockerfile instructions that change files, such as
RUN,COPY, andADD, produce one layer. - Config. A small JSON blob with the settings the runtime needs: environment variables, entrypoint, command, exposed ports, working directory, the ordered list of layer IDs, and build history.
- Manifest. A JSON document that lists the config blob and the layer blobs, each with a media type, size, and digest.
The manifest is the entry point. To pull an image, a client downloads the manifest first. It then downloads the config and each layer the manifest names.
A digest is the SHA-256 hash of a blob's exact bytes, written as sha256: followed by 64 hex characters. Because the name is derived from the content, a blob with a given digest can never change. If one byte differs, the digest differs.
A real manifest
Here is a manifest in the OCI format. The digests are illustrative and the sizes are in bytes.
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"config": {
"mediaType": "application/vnd.oci.image.config.v1+json",
"digest": "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"size": 1469
},
"layers": [
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:a1b2c3d4e5f60718293a4b5c6d7e8f90a1b2c3d4e5f60718293a4b5c6d7e8f90",
"size": 29724913
},
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:0f1e2d3c4b5a69788796a5b4c3d2e1f00f1e2d3c4b5a69788796a5b4c3d2e1f0",
"size": 8123456
},
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:c0ffee00deadbeefc0ffee00deadbeefc0ffee00deadbeefc0ffee00deadbeef",
"size": 412874
}
]
}Three things are worth noticing:
- The manifest contains no file data, only references. It is usually a few kilobytes.
- Layer order is significant. The runtime applies the layers in the listed order to build the root filesystem.
- The image digest you see in
docker images --digestsand in ECR is the SHA-256 of the manifest document itself. Because the manifest lists the digest of every layer and the config, the manifest digest identifies the whole image.
Manifest formats ECR accepts
Two families of manifest formats are in use, and ECR accepts both:
| Format | Manifest media type |
|---|---|
| Docker Image Manifest V2, Schema 2 | `application/vnd.docker.distribution.manifest.v2+json` |
| OCI Image Manifest | `application/vnd.oci.image.manifest.v1+json` |
The structure is nearly identical. The media types differ, and so do the layer media types. Docker's recent default build output varies by version and builder. If you build with BuildKit and add attestations, the result can be an OCI image index instead of a plain manifest, which the next section explains. ECR also accepts the older Docker Schema 1 format for pulling and pushing legacy images, but you will rarely produce it today.
Multi-architecture images and image indexes
A single tag can refer to more than one image. An image index (OCI) or manifest list (Docker) is a manifest whose entries point to other manifests, one per platform:
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.index.v1+json",
"manifests": [
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:a1b2c3d4e5f60718293a4b5c6d7e8f90a1b2c3d4e5f60718293a4b5c6d7e8f90",
"size": 1024,
"platform": { "architecture": "amd64", "os": "linux" }
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:0f1e2d3c4b5a69788796a5b4c3d2e1f00f1e2d3c4b5a69788796a5b4c3d2e1f0",
"size": 1024,
"platform": { "architecture": "arm64", "os": "linux" }
}
]
}When a client pulls the tag, it fetches the index, picks the entry matching its own OS and architecture, and then pulls that manifest and its layers. This is how one tag can serve both x86-64 and Graviton (Arm) hosts.
The index has its own digest, and each child manifest has its own. When you reason about "the digest of this tag," check whether the tag points to a single manifest or to an index. In ECR, an index appears as one image entry whose manifest media type is the index type. The child images are stored in the same repository and are referenced by digest.
How a push uses these objects
The registry protocol is the same Docker Registry HTTP API V2 used by other registries. A push proceeds in this order:
- For each layer and the config blob, the client asks whether the registry already has a blob with that digest.
- Blobs that are missing are uploaded. Blobs that already exist are skipped, which is why Docker prints "Layer already exists."
- The client uploads the manifest last, and ECR associates it with the tag you pushed.
Because blobs are addressed by digest, rebuilding an image whose base layers did not change uploads only the layers that did. The manifest is uploaded last for a reason: it should only appear once every blob it references is present, so a pull never finds a manifest with missing layers.
Pulling reverses the process. The client resolves a tag or digest to a manifest, then downloads blobs it does not already have locally.
Tags are pointers to manifests
A tag is a mutable label that points to a manifest digest. The tag is not part of the image content. Neither the manifest nor the layers contain it. That has two consequences:
- One manifest can have several tags, such as
1.0.0andlatest, all resolving to the same digest. - A tag can be moved. Pushing a different image to
latestre-points that tag. The previous manifest stays in the repository but becomes untagged, and ECR lists it with no tags.
A digest cannot be moved. The next chapters cover how to use this property for reproducible deployments and how to block tag overwrites. For now, remember the rule: tags name, digests identify.
Inspecting stored images with the CLI
You can look at what ECR holds using two commands. The first lists images with their tags, digests, and sizes. The second downloads a manifest as JSON.
aws ecr describe-images \
--repository-name my-app \
--region us-east-1 \
--query 'imageDetails[].{tags:imageTags,digest:imageDigest,sizeBytes:imageSizeInBytes,mediaType:imageManifestMediaType}'
aws ecr batch-get-image \
--repository-name my-app \
--image-ids imageTag=1.0.0 \
--region us-east-1 \
--query 'images[0].imageManifest' \
--output textdescribe-images returns one entry per manifest, so an untagged image shows tags: null. batch-get-image accepts either imageTag=<tag> or imageDigest=<digest> in --image-ids. The output of the second command is the manifest JSON, like the example earlier in this chapter. You can read layer digests and sizes from it directly.
Note that imageSizeInBytes reports the compressed size of the image as stored, which is smaller than what docker images shows for the unpacked image on disk.
Edge cases to know
- Untagged images still count. When a tag moves, the old manifest remains and still uses storage until you delete it or a lifecycle policy expires it. Many "mystery" storage costs come from this.
- An index and its children are separate entries. Deleting only the tag that pointed to an index does not remove the child manifests by itself. Cleanup tooling must account for this.
- Same content, same digest. Pushing identical bytes under a new tag creates no new blobs and no new manifest. It only adds a tag to the existing manifest.
- Rebuilds rarely reproduce digests. Layer tars include timestamps unless the builder normalizes them. Rebuilding the same Dockerfile often yields a different manifest digest even though the source is unchanged. Do not assume a rebuild matches an earlier push.
- Non-image artifacts exist. Registries following the OCI specification can store other artifacts, such as signatures and Helm charts, as manifests with different media types. The same manifest and blob model applies.
Exercise
You push an image to ECR as my-app:1.0.0, then push a different build as my-app:1.0.0 (the repository allows tag overwrites). Describe what exists in the repository afterward, which digests are involved, and why the first image still costs you storage.
Show answer
The repository holds two manifests with two different digests. The tag 1.0.0 now points to the manifest of the second build. The first manifest is still stored, but it is untagged. Its layers also remain, except where the second build shares layers with it, since blobs are identified by digest. Storage is billed on the stored data, so the untagged first image keeps costing money until you delete it or a lifecycle policy expires it. Pulling by the first image's digest still works, because a digest identifies the manifest regardless of tags.
Exercise
A teammate says, "The image digest is the SHA-256 of the image's filesystem." Correct this, and explain why changing one layer changes the image digest.
Show answer
The image digest is the SHA-256 of the manifest document, not of the filesystem. The manifest lists the digest of the config blob and of every layer. If any layer changes, its digest changes, so the manifest text changes, and therefore the manifest's own digest changes. That is why the manifest digest identifies the entire image.