Skip to content
Theory · Your first container · lesson 5 of 7

Where images come from: registries and tags

Cookie cutters do not appear in the kitchen by themselves: someone makes them and someone brings them in. Images, too, live in a shared store that everyone who needs them takes them from. On the first nginx run Docker printed Pulling from library/nginx — that store is where it downloaded the image from.

A registry is a server that stores images and hands them out. The best known registry is Docker Hub at docker.io: Docker turns to it when an image name has no registry in it. GitHub (ghcr.io), GitLab and the cloud providers run registries of their own, and companies often keep a private one.

The full image name

nginx:1.27.3 is a short form. The full name shows when you download the image once more:

Shell
docker pull nginx:1.27.3
TEXT
1.27.3: Pulling from library/nginx
Digest: sha256:bc2f6a7c8ddbccf55bdb19659ce3b0a92ca6559e86d42677a5a02ef6bda2fcef
Status: Image is up to date for nginx:1.27.3
docker.io/library/nginx:1.27.3

Image is up to date means the image on the machine matches the one in the registry, so there is nothing to download. The last line is the full name, and it has four parts:

  • docker.io — the registry, Docker Hub here;
  • library — the section of Docker Hub's official images; your own images have a user or organization name in this place;
  • nginx — the repository that holds every version of one image;
  • 1.27.3 — the tag.

A tag is a version label inside a repository. One repository holds many tags: 1.27.3, 1.27.3-perl, latest and others. The docker images command lists the images already on your machine.

How a registry hands out layers

In a registry an image is stored as a manifest — a list of its layers, each with a digest, a fingerprint of its content. You saw the same kind of fingerprint in the Digest: line, only for the whole image. When Docker downloads an image, it fetches the manifest first, compares the layers' digests with the ones already on the machine and downloads only the missing layers.

You can see it with the nginx:1.27.3-perl image, which is built on top of nginx:1.27.3:

Shell
docker pull nginx:1.27.3-perl
TEXT
1.27.3-perl: Pulling from library/nginx
49eac3ecc293: Pull complete
ee083de5ceda: Already exists
5afd6583b29c: Already exists
a982d09283a6: Already exists
1e8aefce6919: Already exists
8c2914db26a3: Already exists
c29f5b76f736: Already exists
ab571a6216e3: Already exists
de2446fbd48b: Download complete
a6eb3e82325c: Download complete
Digest: sha256:43b7ebe48e8553d75bf180747384aade3b5644e3c9190c4cf5c4ea829da1e644
Status: Downloaded newer image for nginx:1.27.3-perl
docker.io/library/nginx:1.27.3-perl

Seven layers are marked Already exists: they are the same seven layers nginx:1.27.3 has, and they are already on the machine. Only one new layer was downloaded, 49eac3ecc293.

docker push works the other way round: it sends the registry the manifest and the layers the registry does not have yet. For a layer the registry already stores, the command prints Layer already exists and sends nothing. To push images to Docker Hub, you first sign in with docker login.

This is where the cutter picture stops working. A shop hands over a whole cutter, while a registry hands out an image layer by layer, and only the layers you lack.

Interviewers like to ask what a registry is and what happens on docker push and docker pull. The answer fits one idea: the registry and the client compare layer digests and transfer only the layers the other side lacks.

Common mistake

The image was pulled without a tag:

Shell
docker pull nginx
TEXT
Using default tag: latest
latest: Pulling from library/nginx
37fb86c2a767: Pull complete
6d2e43921e9e: Pull complete
512ac5e7ce8e: Pull complete
1724c05f72c6: Pull complete
bbb080c71d50: Pull complete
1962e1ff75b4: Pull complete
7cb4701ce7cd: Pull complete
4582dace95e2: Download complete
d2c7e31f04a3: Download complete
Digest: sha256:165ddde8751e75a1c907d24ef10d9f6deb08b57e0fe56caf67512486aff76d82
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

With no tag, Docker filled in latest. It is not "the newest version" by any rule, but an ordinary tag the image's authors move to each new release. On the day of this run latest held nginx 1.31.8, and a month later it will hold another version. A colleague who ran the same command earlier got a different nginx, and "works on my machine" is back. Name a specific tag: nginx:1.27.3.

Key points

  • A registry stores and hands out images; with no registry named, Docker turns to Docker Hub, docker.io.
  • The full image name is registry, section, repository and tag: docker.io/library/nginx:1.27.3.
  • docker pull and docker push compare layer digests and transfer only the missing layers.
  • Without a tag Docker takes latest, which points at different versions over time.