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.
docker pull python:3.12-slimdocker history python:3.12-slim # one row per layerdocker image ls # local images and their sizesWhy layers matter
Section titled βWhy layers matterβ- 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.
Tags and digests
Section titled βTags and digestsβ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.