Sub topic 1
How container registries work
Prerequisites
This chapter assumes you can build an image with docker build and run it with docker run. You should know what a Dockerfile is and be comfortable in a terminal. You do not need an account on any registry yet. Later chapters cover GitHub Container Registry (GHCR) and Amazon Elastic Container Registry (ECR).
What a registry is
A container registry is a server that stores container images and hands them out on request. When you run docker pull nginx, your Docker client asks a registry for the image and downloads it. When you run docker push, the client uploads an image to a registry.
Registries speak a standard HTTP API defined by the Open Container Initiative (OCI) Distribution Specification. Because the API is standard, one client such as Docker, Podman, or containerd can talk to GHCR, ECR, Docker Hub, and a self-hosted server alike.
Registries, repositories, and images
Three terms are easy to mix up:
| Term | Meaning | Example |
|---|---|---|
| Registry | The server that hosts images | `ghcr.io` |
| Repository | A named collection of versions of one image | `your-name/my-app` |
| Tag | A human-readable label that points to one version | `1.0.0` |
A registry holds many repositories. A repository holds many tagged versions of one application. The next chapter covers how these parts combine into a full image reference.
What is inside an image
An image is not a single file. It is made of three kinds of stored objects:
- Layers. Each layer is a compressed archive of filesystem changes, usually produced by one Dockerfile instruction. Layers are identified by a hash of their content.
- Config. A JSON file with the image's settings, such as the default command, environment variables, and the ordered list of layers.
- Manifest. A JSON document that lists the config and every layer by hash and size. The manifest is the entry point. To pull an image, a client fetches the manifest first.
Because layers are named by their content hash, two images that share a base layer share the stored data. The registry keeps one copy.
What happens on push and pull
On a pull, the client fetches the manifest, compares the layer hashes with what it already has locally, and downloads only the missing layers. On a push, the client does the reverse. It asks the registry which layers it lacks, uploads those, and uploads the manifest last. This is why a second push of a slightly changed image is fast.
You can see these objects yourself. The command below prints the manifest of a public image. It needs a Docker installation with the buildx plugin, which current Docker releases include.
docker buildx imagetools inspect alpine:3.20 --rawThe output is JSON. For a multi-platform image it is an index, which is a manifest that lists one manifest per platform, such as linux/amd64 and linux/arm64. The client picks the entry that matches its own platform.
Public and private registries
Some registries allow anyone to pull without logging in. Others require credentials for every request, or only for private repositories. Pushing almost always requires credentials. The reasons to run a private registry, and how to log in, come in the next chapters.
Exercise
You change one line near the end of a Dockerfile and push the image again to the same repository. Why does the second push upload much less data than the first, and which object does the client upload last?
Show answer
The registry already stores the earlier layers, which are identified by content hash, so the client uploads only the layers that changed. The manifest is uploaded last, because it refers to all the layers and the registry needs them in place first.