zstd Container Images: 20% Smaller, Faster Pulls

zstd container images compared with gzip layers in a build pipeline

Most container images ship with gzip-compressed layers, and most teams never chose that. A developer building the node image for a browser-based Kubernetes experiment called Tabernetes switched the layer compression to zstd and got an image about 20% smaller, with no change to the files inside. zstd container images have been allowed by the OCI image specification for years, yet gzip is still what almost every registry serves.

Why gzip is still the default

Under the hood an image bundles a manifest, a config file and several layers. Every layer is a tar archive holding whatever one build step added or changed, and registries keep a compressed copy of it. The manifest names the compression through the layer’s media type, so a gzip layer ends in tar+gzip and a zstd layer ends in tar+zstd.

Docker used gzip from the start, long before the OCI spec existed. zstd arrived in 2016. It unpacks quickly at every setting, and its many levels let teams choose between faster builds and smaller output. gzip gives no such choice.

What the measurements show

To test it, the author took three popular Docker Hub images (nginx, postgres and python-slim), flattened each into one layer and rebuilt them with BuildKit v0.34 on an Apple M1. The build cache was cleared before every run so no old blobs got reused.

  • Raising gzip to level 9 costs three to four times the CPU for a gain under 1%.
  • Default zstd compresses about four times faster than default gzip, and the result is 10% smaller.
  • zstd level 19 takes roughly 15 seconds longer than gzip across all three images and produces layers 21% smaller.
  • Unpacking is about six times quicker with zstd, and the level makes no difference there.

A higher level costs extra time once, in the CI job, and every node that later pulls the image benefits. Loading postgres:17 into Docker with the containerd image store took 6.5 seconds with gzip and 5.3 to 5.4 seconds with zstd, about 18% faster. A real registry pull should also download up to 20% less data, though that wasn’t measured.

Level 19 doesn’t match what the zstd command-line tool would give. BuildKit relies on a Go-only encoder library rather than libzstd, and that library folds every level above 10 into one “best” mode, roughly equal to zstd level 11.

Why pull time matters

A pod scheduled onto a node that lacks its image has to wait for a pull. That covers rollouts, new nodes from the autoscaler, and pods rescheduled after a failure. A smaller download and faster unpacking both shorten that wait, which the author considers a bigger gain than saved registry storage.

Building with BuildKit

The setting goes on the image exporter. The exporter takes four options that matter: compression=zstd, compression-level, force-compression=true and oci-mediatypes=true. You need a docker-container builder, or Docker with the containerd image store, which new installs have used by default since Docker 29. The older classic image store can’t write zstd layers.

Two cache traps

The first trap: BuildKit compresses only the layers it creates in the current build. Existing layers, including every layer of the base image in your FROM line, stay gzip unless force-compression=true is set. Since the base image usually holds most of the bytes, you can end up with a mostly gzip image while the build script says zstd.

The compression level isn’t part of the cache key either. After building a layer at level 3, a rebuild at level 19 returned the level 3 blob with the same digest. On a long-lived builder or shared cache, prune it once after changing the level.

The author checks the result in the registry instead of trusting flags: inspect the manifest with docker buildx imagetools inspect –raw and confirm every layer’s media type ends in tar+zstd.

Podman, Buildah and converting old images

Podman and Buildah store layers uncompressed locally, so compression is chosen at push time with –compression-format zstd and a level from 1 to 20. A default can be set in containers.conf. Podman also supports zstd:chunked, which lets CRI-O and Podman pull only the files a node lacks; other runtimes treat it as plain zstd.

To try zstd before changing any build, skopeo and regclient can recompress an image while copying it to another registry. With skopeo, add –dest-force-compress-format, or it may reuse the existing gzip blobs.

Who can pull zstd images

Any client that doesn’t recognise tar+zstd fails the pull with an unsupported media type error, and nothing falls back to gzip. Kubernetes itself doesn’t care, because the container runtime handles layers, and current containerd 1.7 and 2.x and CRI-O all pull zstd. Major registries from Docker Hub and GHCR to ECR, ACR, Quay and Harbor serve it too.

The risk sits in the tooling around the cluster:

  • CI runners and laptops running a Docker Engine older than 23.0.
  • Scanners, SBOM tools and admission controllers that unpack layers themselves, where the exact version in use matters.
  • eStargz and SOCI lazy pulling, which are built around gzip. BuildKit can’t yet build zstd:chunked, so you pick one or the other.
  • Ancient self-hosted registries, or proxies that only allow listed media types.

For public images, the author would stay with gzip on the main tag and add zstd under a separate tag until old clients disappear. A 10 MB distroless image with one Go binary won’t pull noticeably faster either way.

The recommended setup for internal images

For images that run on your own clusters, the author builds everything with compression=zstd, force-compression=true and oci-mediatypes=true. Level 9 is the everyday choice: build time is close to level 3 and the image is about 5% smaller. Level 19 is reserved for large, frequently pulled images such as node, CI runner and ML images. Public images mirrored into an internal registry get recompressed to zstd on the way in. Before switching, audit CI for old Docker Engines and check which scanner versions the pipeline runs.

Source: Jan-Otto Kröpke

Written by

Saksham Bhargava

Saksham Bhargava runs Alteroid and has been writing about consumer technology for over five years, covering iPhone, Android, Windows, AI tools and gaming. With an MCA and six years of hands-on web development experience, he tests the features he writes about on his own devices and focuses on clear, practical guides that solve real problems. Away from the screen, he enjoys travelling to places most tourists skip.