1. An Image Is a Stack of Layers
Every instruction that changes files during a build creates a new layer — a read-only "diff" of what changed. The final image is all layers stacked together. Press the button to stack them up:
The stack is empty — press "Add next layer".
🥞 Analogy: An image is a stack of pancakes. Each pancake (layer) is cooked once and never changed. Ten students can share the same bottom pancakes (base OS) — only the top pancake differs. When a container runs, Docker puts a sheet of baking paper on top (the writable layer): the container scribbles on the paper, never on the pancakes. Throw the container away → only the paper is lost.
2. Why Layers Matter: Sharing & Caching
✅ Practical rule that follows: in a Dockerfile, put things that rarely change (OS, dependencies) early, and things that change often (your code) late — so most layers stay cached on every rebuild. Chapter 3 shows this in action.
3. Names & Tags — Identifying Images
⚠️ The "latest" trap:
latest is just the default tag name — it is NOT automatically the newest version, and it changes over time. In real deployments always pin a specific tag like nginx:1.25, never nginx:latest.4. Moving Images Around — pull, push, build
# The three commands of the cycle: docker build -t team/studentfees:v2.1 . # Dockerfile → local image docker push team/studentfees:v2.1 # local image → registry docker pull team/studentfees:v2.1 # registry → any other machine
5. Inspecting What You Have
| Command | Shows you |
|---|---|
docker images | All images on this machine (name, tag, size) |
docker history nginx | The layers of an image and which instruction made each |
docker inspect nginx | Full JSON details (env vars, ports, entrypoint…) |
docker rmi nginx:1.25 | — removes an image (frees disk) |
docker system df | How much disk images/containers/volumes use |