Skip to content

Images and layers

An image is a stack of read-only layers. Each layer records the files added, changed or removed by one build step. When you run a container, Docker adds a thin writable layer on top.

Terminal window
docker pull python:3.12-slim
docker history python:3.12-slim # one row per layer
docker image ls # local images and their sizes
  • Sharing β€” layers are identified by a hash of their content. Ten images built on the same base store that base once.
  • Caching β€” when you rebuild, Docker reuses every layer whose inputs haven’t changed. Order your build steps from least to most frequently changing to get the most cache hits. You’ll use this in the next chapter.

A tag like python:3.12-slim is a movable pointer β€” it can point at a different image tomorrow. A digest (python@sha256:…) never changes. Production deployments pin digests for exactly that reason.

Check your understanding

1. Two images share the same base layers. How many copies of those layers are stored on disk?