Sub topic 11
What a registry does
This chapter assumes you can run docker run, know that an image is a stack of layers, and have seen a tag such as myapp:1.0. It explains what sits on the other end when you push or pull.
A registry is an HTTP server for image content
A registry stores images and serves them over an HTTP API. The API is defined by the OCI Distribution Specification. Docker Hub, GitHub Container Registry, Amazon ECR, and the open-source registry:2 image all implement it.
A registry holds many repositories. A repository holds the versions of one image, which you reach by tag or by digest. In registry.example.com/team/myapp:1.0, the host is the registry, team/myapp is the repository, and 1.0 is the tag. If you leave out the host, Docker assumes Docker Hub.
What it stores
A registry keeps three kinds of things.
| Object | Identified by | Can change? |
|---|---|---|
| Blob (a layer or an image config) | Its digest | No |
| Manifest (JSON listing a config and layers) | Its digest | No |
| Tag | A name inside one repository | Yes |
A tag is only a pointer to a manifest digest. Pushing myapp:1.0 again moves the pointer to a new manifest. The old manifest stays reachable by its digest until something removes it.
What happens on a pull
The client asks for the manifest first. It then downloads only the blobs it does not already have locally.
A push runs in the opposite order. The client uploads blobs first and the manifest last. This guarantees that a manifest never points at a blob the registry lacks.
Because blobs are addressed by digest, two images that share a base layer share one stored blob. A registry also skips any blob it already has, so repeated pushes upload very little.
Looking at the API yourself
If a registry is listening on localhost:5000 and myapp:1.0 has been pushed to it, you can query it with curl:
curl -s http://localhost:5000/v2/_catalog
curl -s http://localhost:5000/v2/myapp/tags/list
curl -s -H "Accept: application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json" \
http://localhost:5000/v2/myapp/manifests/1.0The first call lists repositories. The second lists the tags in one repository. The third returns the manifest as JSON.
Common errors
manifest unknown: the tag or digest does not exist in that repository. Check the spelling and the repository path.unauthorized: the registry requires a login or your account lacks access. Logging in is covered in a later chapter.- Pulling the wrong image: a missing host silently points at Docker Hub. Write the full reference for private registries.
Exercise
You push myapp:1.0 twice. The second push contains a rebuilt image with different content. What happens to the first image in the registry?
Show answer
The tag 1.0 now points to the new manifest. The first manifest and its blobs remain stored and can still be pulled by digest, until a cleanup process removes them.