Docker has a small vocabulary, and once it clicks, every command makes sense. This lesson defines each term, shows how they connect, and gives you one command per idea so you can see it on your machine.
The building blocks at a glance
| Concept | What it is | You meet it in |
|---|---|---|
| Image | Read-only template: files plus metadata such as the start command | docker pull, docker build |
| Layer | One read-only filesystem diff inside an image | docker history |
| Container | A running or stopped instance of an image, with its own writable layer | docker run, docker ps |
| Dockerfile | The recipe that builds an image, one instruction per step | docker build |
| Registry | A server that stores and distributes images | docker push, docker pull |
| Repository and tag | An image name and a version label, like nginx:1.27 | every image reference |
| Volume | Storage managed by Docker that outlives containers | docker volume, -v |
| Network | A virtual network that lets containers reach each other by name | docker network |
| Compose | A YAML file describing a multi-container application | docker compose up |
Images are made of layers
Each instruction in a Dockerfile that changes files produces a layer. Layers are stacked, cached and shared: ten images based on node:22-alpine store that base only once on disk.
$ docker history --format 'table {{.CreatedBy}}\t{{.Size}}' hello-node:1.0
CREATED BY SIZE
CMD ["node" "server.js"] 0B
EXPOSE map[3000/tcp:{}] 0B
ENV PORT=3000 0B
COPY server.js . # buildkit 8.19kB
WORKDIR /app 0B
... 152MB
Instructions like ENV and CMD only change metadata, so their layers are empty. Lesson 8 shows how ordering layers well makes builds much faster.
Containers add a writable layer
When a container starts, Docker puts a thin writable layer on top of the image’s read-only layers. Anything the process writes goes there:
$ docker run --name scratchpad alpine sh -c 'echo hi > /note.txt'
$ docker diff scratchpad
A /note.txt
$ docker rm scratchpad
scratchpad
A means added. Removing the container throws the writable layer away, which is why important data belongs in a volume (lesson 9).
Names, registries, tags and digests
A full image reference has up to four parts:
ghcr.io/jeff/api:1.4.2
ghcr.iois the registry. When omitted, Docker uses Docker Hub (docker.io).jeff/apiis the repository. Official Docker Hub images likenginxlive underlibrary/.1.4.2is the tag. When omitted, Docker useslatest, which is just a label, not “the newest”.- A digest such as
@sha256:3b1f...pins the exact content and never changes.
$ docker pull redis:7.4
$ docker images redis
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 7.4 8e1f3c5a9d2b 2 weeks ago 117MB
The container lifecycle
A container moves through a few states, and every state has a command:
- Created:
docker create(or the first half ofdocker run). - Running:
docker start, ordocker rundirectly. - Paused:
docker pausefreezes the processes;docker unpauseresumes. - Exited: the main process ended, or you ran
docker stop. - Removed:
docker rmdeletes the container and its writable layer.
$ docker ps -a --format 'table {{.Names}}\t{{.Status}}'
NAMES STATUS
api Up 3 hours
worker Exited (1) 10 minutes ago
Networks connect containers
Containers on the same user-defined network can reach each other by name, through Docker’s built-in DNS:
$ docker network create appnet
$ docker run -d --name cache --network appnet redis:7.4
$ docker run --rm --network appnet redis:7.4 redis-cli -h cache ping
PONG
No IP addresses and no published ports were needed; -p is only for reaching a container from outside Docker.
Compose ties it together
Compose describes images, containers, networks and volumes for a whole application in a compose.yaml file. You saw one in lesson 2; it uses every concept on this page, and docker compose up creates them in the right order.
Mental model: a Dockerfile builds one image; a Compose file runs many containers from images and wires them together.
Exercise
Containers web and db are attached to the same user-defined network. How should web connect to the database?
Show answer
Answer: D. User-defined networks have built-in DNS that resolves container names. No port needs to be published for container-to-container traffic, and container IPs change on every restart.
Key takeaways
- Images are stacks of cached, shareable layers; containers add one writable layer on top.
- A reference like
registry/repository:taglocates an image; a digest pins its exact content. - Data written inside a container disappears with it unless it lives in a volume.
- User-defined networks let containers talk to each other by name.
FAQ
What is the difference between an image ID and a digest?
The image ID identifies the image configuration on your machine. The digest identifies the image manifest in a registry. Use digests when you need a reference that is identical everywhere.
Why are there so many dangling images named none?
They are old layers left behind when a tag moves to a new build. docker image prune removes them safely.
What does OCI mean?
The Open Container Initiative defines open standards for image formats and runtimes. Docker, Podman, containerd and Kubernetes all speak OCI, so an image built with one runs with the others.