Docker: what's the difference between an image and a container?
asked 5 months ago247 viewsen
I keep mixing up images and containers. docker ps shows containers, docker images shows images. How do they relate?
AI diagnosis
AI-generated. Not an answer — the community below confirms or corrects it. Always verify before relying on it.
2 Answers
An image is a read-only template: your app, its dependencies and the OS files, built from a Dockerfile. A container is a running instance of an image, with its own writable layer, process, and network.
Think of it as class vs object: one image can run as many containers.
docker build -t myapp:1.0 . # Dockerfile -> image
docker run -d --name web1 myapp:1.0 # image -> container
docker run -d --name web2 myapp:1.0 # a second container, same image
Files written inside a container disappear when it's removed. Use volumes for data that must persist (databases, uploads).
Sign in to tell others whether this worked.
Another analogy: an image is like an .iso or installer, a container is the installed, running program. docker ps -a shows stopped containers too, and those still take disk space until you docker rm them.
Sign in to tell others whether this worked.
Sign in and verify your email to post an answer.