Tags and layers
Why latest does not mean “fresh” and how images share disk space.
An image name consists of a repository and a tag: in postgres:16 the repository is postgres and the tag is 16. If you leave the tag out, Docker uses latest. It is an ordinary tag name, not a promise of freshness: the image author may never update latest at all, or may point it at an old branch. On servers you specify a concrete version, otherwise the same command will pull different images on different days.
A tag can be moved to another image, so the most precise address is the digest: a content hash of the form sha256:.... An image referenced by digest never changes. In practice people usually pin a version with a tag (postgres:16.4) and use the digest where full reproducibility matters.
An image is made of layers. Each layer is a set of file system changes on top of the previous one, and layers are read-only. If two images start from the same base image, its layers are stored on disk once. A container adds its own thin writable layer on top; remove the container and only that layer disappears.
docker pull postgres:16.4
docker images
# REPOSITORY TAG IMAGE ID SIZE
# postgres 16.4 9c1f... 432MB
docker image inspect postgres:16.4 --format '{{.RepoDigests}}'
The last command shows the digest you can use to pin exactly this image.
A common mistake is to add up the sizes from docker images and be alarmed by the total. The SIZE column shows the full size of each image including shared layers, while on disk shared layers are stored once. How much space is really used is shown by docker system df.
Practice
What latest means
What does the
latesttag guarantee?- That it is the newest stable version
- Nothing: it is an ordinary tag used by default
- That the image was built within the last day
- That Docker has scanned the image for vulnerabilities
Image layers
Which statements about layers are true? Mark all.
- Image layers are read-only
- A base layer shared by two images is stored on disk once
- A container writes its changes directly into the image layers
- Removing a container removes its writable layer
The default tag
Which tag will Docker use in
docker pull redisif no tag is given?