CoursesDocker from the kernel up
Puzzle 12 · 13 of 17
Where images live on disk
Puzzles 9 to 11 followed layers from a tar archive to an overlay mount. Here's where Docker keeps them in between, why an image takes more disk than its download, and how to tell which of Docker's two ways of storing images your machine uses.
All puzzles in this course
The problem
Puzzle 9's alpine:3.20 downloaded 3.6 MB, and its layer unpacks to 8.1 MB of files. On the run behind this page, docker image ls said it takes 12.2 MB. That's neither number: more than both. And puzzle 10's mount line listed directories with long containerd names, while older guides point to a different folder altogether. Which is right, and where do your images really live?
See it
Scroll sideways to see the full diagram.
Alpine's layer, 25f1…, arrives as a gzip-compressed tar: 3,630,321 bytes, about 3.6 MB.
Step 1 of 6With the containerd image store, Docker 29's default for new installations, containerd keeps that blob exactly as it arrived, in its content store.
Step 2 of 6Then a snapshotter, here overlayfs, unpacks it into a directory of plain files, 8.1 MB. That directory is a lower directory of every container from the image.
Step 3 of 6docker image lsshows two sizes for each image. Predict: is the space on disk closer to the download, or bigger?Step 4 of 6Bigger: 12.2 MB on disk against 3.71 MB of content, because each layer is kept twice, compressed and unpacked.
Step 5 of 6Installations upgraded from before Docker 29 keep the older storage driver, overlay2. It stores only the unpacked files: 7.81 MB for the same image on a second daemon.
Step 6 of 6
The building block
Docker has two ways to keep images, and a machine uses one of them.
The containerd image store is the default for Docker Engine 29 and later on new installations. It hands image storage to containerd (the program from puzzle 8), which keeps each layer twice:
- Compressed, exactly as it was downloaded, in its content store: on the test machine, Alpine's layer is the file …/io.containerd.content.v1.content/blobs/sha256/25f1d6b1951a…, 3,630,321 bytes.
- Unpacked, as a directory of plain files, prepared by a snapshotter: the containerd component that turns layers into directories (snapshots) and stacks them for a container. The default snapshotter is overlayfs; Alpine's layer became …/snapshots/1/fs, 8.1 MB, the directory you saw as a lowerdir in puzzle 10.
That's why docker image ls shows two sizes:
$ docker image ls alpine:3.20
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
alpine:3.20 d9e853e87e55 12.2MB 3.71MB
Content size is what was downloaded (the compressed layer plus a few small JSON files); disk usage counts the compressed copy and the unpacked one. Docker's documentation says it plainly: the containerd image store uses more disk space because it stores images in both compressed and uncompressed formats. In return, it can keep images for several kinds of processor and the extra files some images carry (puzzle 16), and save or upload an image without packing its layers again. The two copies have different jobs: containers mount the unpacked snapshot, while docker save and uploading the image (puzzle 14) need the compressed blob; Docker's documentation warns that with content missing, save can produce an incomplete archive and uploads can't send the missing layers.
The older way is a storage driver. Installations upgraded from before Docker 29 keep using one until someone switches, and on Linux it is almost always overlay2. It stores only the unpacked layers, under /var/lib/docker/overlay2, and builds the same kind of overlay mount for each container. The mechanism of puzzles 10 and 11 is the same with either: read-only lower directories, one writable upper directory per container.
Which one does your machine use? docker info says:
$ docker info --format '{{.Driver}} {{.DriverStatus}}'
overlayfs [[driver-type io.containerd.snapshotter.v1]]
"overlayfs" with driver-type io.containerd.snapshotter.v1 is the containerd image store with its overlayfs snapshotter. "overlay2" would be the storage driver. On the test machine dockerd started its own containerd, so the store sits under /var/lib/docker/containerd/daemon/; where it sits on yours depends on how containerd runs there, which is one more reason to trust docker image ls and docker system df rather than walking the folders. Docker's documentation also warns against changing anything under /var/lib/docker by hand.
Two edges. The containerd image store doesn't work with puzzle 5's userns-remap setting, so a daemon using that keeps the storage driver. And switching between the two doesn't move images: Docker's documentation says the other backend's images and containers stay on disk but become hidden until you switch back.
The analogy
The building keeps two copies of every delivery: the sealed box exactly as the courier brought it, on a shelf in the post room, and the unpacked furniture laid out in a storeroom, ready to show through any flat's floor. The old building kept only the unpacked furniture: less room, but nothing to hand straight back to a courier.
Run it yourself
On a Linux machine with Docker. Predict, before running, whether your disk usage is bigger than your content size, and which storage your daemon reports.
docker info --format '{{.Driver}} {{.DriverStatus}}'
docker pull alpine:3.20
docker image ls alpine:3.20
docker system df
With the containerd image store, expect disk usage well above content size, as above. With overlay2, docker info prints overlay2 and its own details instead.
Check yourself
Sources
- Docker docs: containerd image store ("The containerd image store is the default storage backend for Docker Engine 29.0 and later on fresh installations. If you upgraded from an earlier version, your daemon continues using the legacy graph drivers (overlay2) until you enable the containerd image store."; "containerd stores images in both compressed and uncompressed formats, while the legacy drivers stored only the uncompressed layers. When you pull an image, containerd keeps the compressed layers (as received from the registry) and also extracts them to disk."; "Building and storing multi-platform images locally."; "docker save can fail or produce an incomplete archive without reporting an error. docker push cannot upload missing layers"; "The containerd image store is not available when using user namespace remapping ( userns-remap )."; "Switching storage backends temporarily hides images and containers created with the other backend. Your data remains on disk.")
- Docker docs: OverlayFS storage driver ("After downloading a five-layer image using docker pull ubuntu , you can see six directories under /var/lib/docker/overlay2 ."; "Don't directly manipulate any files or directories within /var/lib/docker/ .")
- Docker docs: Engine 29 release notes ("containerd image store is now the default for fresh installs .")
- The docker info line, the docker image ls line (taken right after pulling alpine:3.20, before puzzle 16 pulled a second platform), the blob size and the snapshot size were read in this session with Docker Engine 29.9.2 on the test machine (Ubuntu 24.04 userland in a Firecracker microVM, custom kernel 6.18.44, cgroup v1).
What you now know
Docker 29 keeps images in the containerd image store by default on new installations: each layer is kept compressed, as downloaded, in containerd's content store, and a snapshotter (overlayfs) unpacks it into a directory that becomes a lower directory. So an image takes its download size plus its unpacked size. Installations upgraded from older Docker keep the overlay2 storage driver, which stores only the unpacked layers; docker info tells you which one you have.
Answer every question above correctly to unlock the next puzzle.
Something wrong or unclear on this page? Tell me: a puzzle that didn't click is a bug in the puzzle.