Docker Images & Containers
Part of the Backend Developer Roadmap
In short
Images and containers get mixed up all the time. One is the mould, the other is what comes out of it. Get this straight and every Docker command makes sense.
An image is a read-only template (built from a Dockerfile); a container is a running instance of that image — understanding this distinction clarifies most of Docker's mental model.

Think of it like this
The idli stand and the idlis
One steel idli stand can make plate after plate of idlis, all identical. You eat one, the stand isn't affected. Throw an idli away and the stand is still there for tomorrow. The image is the stand; each container is an idli.
Watch it happen
Layers of an image, plus a container on top
Top of the stack is coloured
1/6The bottom layer is a tiny Linux file system from the base image.
The big ideas
What you need to know
Images are stacked layers
Layers are read-only and shared. Ten images on Node 22 store the Node layer once.
Containers add a writable layer
Each container writes to its own thin top layer. Remove the container, and those changes vanish.
Tags name versions
chai-api:1.0 and chai-api:1.1 are different images. A tag is a label you can move, so pin exact ones for deploys.
Clean up
Old images and stopped containers eat disk space. docker system prune clears the unused ones.
See it in code
Walk through the code
1docker build -t chai-api:1.0 . # recipe -> image2docker images # list images3 4docker run -d --name api1 -p 3001:3000 chai-api:1.05docker run -d --name api2 -p 3002:3000 chai-api:1.06 7docker exec -it api1 sh # look inside a running container8docker rm -f api1 # container gone, image stays9docker history chai-api:1.0 # see the image's layers1/4Build once to get an image, then confirm it's listed with its tag and size.
Two containers from one image run independently: different names, ports and writable layers, same starting files.
Save yourself the pain
Common mistakes
Oops
Editing files inside a running container to fix a bug.
Do this instead
The fix disappears with the container. Change the code, rebuild the image and recreate the container.
Oops
Running docker rmi and expecting running containers to stop.
Do this instead
Docker won't remove an image a container is using. Stop and remove the containers first.
Your mission
Prove the writable layer is temporary
Quick check
You delete a container. What happens to the image it came from?
Go deeper
- 1Build an image, then run multiple containers from the same image simultaneously.
- 2Learn `docker ps`, `docker stop`, `docker rm` for managing running containers.
- 3Inspect an image's layers with `docker history`.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.