Docker: what's the difference between an image and a container?

asked 5 months ago247 viewsen

1

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.

asked 5 months ago

2 Answers

9
✓
✓ Accepted answer

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.

answered 5 months ago
1

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.

answered 5 months ago

Sign in and verify your email to post an answer.