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

poze 5 months ago243 gadeen

1

I keep mixing up images and containers. docker ps shows containers, docker images shows images. How do they relate?

Dyagnostik IA

Se IA ki fè l. Se pa yon repons — kominote a anba a konfime oswa korije l. Toujou verifye anvan ou fye l.

poze 5 months ago

2 Repons

9
✓
✓ Repons yo aksepte

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).

Konekte pou di lòt moun si li te mache.

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.

Konekte pou di lòt moun si li te mache.

answered 5 months ago

Sign in and verify your email to post an answer.