Sub topic 1
What an ECR registry stores: images, layers, and manifests
Before you create repositories or push anything, it helps to know what ECR holds when you push an image. This chapter explains the three pieces: layers, the image configuration, and the manifest. Later chapters on tags, digests, scanning, and lifecycle policies build on them.
Prerequisites
This chapter assumes you can build and run an image with Docker and write a basic Dockerfile. You also need the AWS CLI installed with working credentials. You don't need to have used ECR yet.
An image is a set of content-addressed blobs
A container image is not one file. It is a collection of separate pieces, and each piece is identified by a digest. A digest is a SHA-256 hash of the piece's bytes, written as sha256: followed by 64 hexadecimal characters. Two pieces with the same bytes always have the same digest. This is called content addressing.
An image has three kinds of parts:
| Part | What it contains | Typical size |
|---|---|---|
| Layer | A compressed archive of filesystem changes, usually produced by one Dockerfile instruction | Kilobytes to hundreds of megabytes |
| Image configuration | JSON with the entrypoint, environment variables, working directory, architecture, and the ordered list of layer IDs | A few kilobytes |
| Manifest | JSON that lists the digest, size, and media type of the configuration and of each layer | A few kilobytes |
ECR stores all three. The manifest is the entry point. When a client pulls an image, it fetches the manifest first, then downloads the configuration and the layers the manifest names.
Why layers matter for pushes and storage
Layers are immutable. Changing one line near the end of a Dockerfile produces a new top layer and leaves the layers below it unchanged. When you push, Docker asks the registry which layers it already has. For each layer already present in the repository, Docker prints Layer already exists and uploads nothing. Only new layers travel over the network.
This is why Dockerfile order affects push time. Put rarely changing steps, such as installing dependencies, before frequently changing steps, such as copying your source code.
ECR charges for the data stored in your repositories, so large layers cost money for as long as an image that uses them exists. Lifecycle policies, covered later, remove old images to control this.
Looking at a manifest
You can read a manifest directly. This command assumes a repository named my-app that contains an image tagged 1.0.0:
aws ecr batch-get-image \
--repository-name my-app \
--image-ids imageTag=1.0.0 \
--query 'images[].imageManifest' \
--output text \
--region us-east-1The output has this shape. The digests are shortened here:
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"size": 7023,
"digest": "sha256:bbb..."
},
"layers": [
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 32654,
"digest": "sha256:ccc..."
}
]
}The digest of the manifest file itself is the image digest. It is the value you will use in a later chapter to pull an image by digest. Because the manifest contains the digest of every layer, a change to any layer changes the image digest.
Formats ECR accepts
ECR accepts Docker Image Manifest V2 Schema 2 and Open Container Initiative (OCI) image manifests. A multi-architecture image adds one more level. Its top-level document is a manifest list (Docker) or an image index (OCI). That document points to one separate manifest for each platform, such as linux/amd64 and linux/arm64. A client picks the manifest that matches its own platform.
Exercise
You change one line in the last COPY instruction of a Dockerfile and push again. Which parts of the image are new in ECR, and why does the image digest change even though most layers are unchanged?
Show answer
The new top layer, the image configuration (its layer list changed), and the manifest are new. The lower layers already exist, so Docker skips them. The image digest is the hash of the manifest, and the manifest lists the new layer and configuration digests, so its hash changes.