Images and layers
Understand how an image is built from stacked read-only layers and why that makes builds fast.
Open this lesson in the learning hubKey points
- An image is a stack of read-only layers plus metadata. A container is that stack plus one thin writable layer on top.
RUN,COPYandADDeach add a layer. ENV, WORKDIR and CMD only change metadata.- Layers are content-addressed by digest. Images that share a base share those bytes on disk and skip them on pull.
- Deleting a file in a later layer only hides it. The bytes still ship, so never
COPYa secret and thenRUN rm. - Writes inside a running container land in its writable layer and vanish on
docker rm.
Example
docker pull eclipse-temurin:21-jre
# every layer, newest first, with the instruction that made it
docker image history eclipse-temurin:21-jre
# the raw layer digests
docker image inspect eclipse-temurin:21-jre --format '{{json .RootFS.Layers}}'
Layers are append-only, cached and shared. Deleting never shrinks an image.
This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Docker course, and every lesson in it is listed on the Docker contents page.