Docker: what's the difference between an image and a container?
posée 5 months ago246 vuesen
I keep mixing up images and containers. docker ps shows containers, docker images shows images. How do they relate?
Diagnostic IA
Généré par IA. Ce n'est pas une réponse — la communauté ci-dessous le confirme ou le corrige. Vérifiez toujours avant de vous y fier.
2 réponses
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).
Connectez-vous pour dire si ça a marché.
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.
Connectez-vous pour dire si ça a marché.
Sign in and verify your email to post an answer.