What is the difference between a Docker image and a container?
Options
- The image is a read-only template; the container is a running instance (Correct option)
- The image is a running program, and the container is just a file
- They are the same thing, only named differently by each tool
- The image is a database, and the container is a server
Answer
The image is the read-only template; the container is a running instance created from it
Why
Think of the same relationship as class and object, or recipe and dish.
You build an image from a Dockerfile (the instructions). You run it with docker run, and each run creates a container. You can start many containers from one image.
Images are stored in a registry such as Docker Hub.
docker build -t my-app . # build an image
docker run -p 8080:8080 my-app # start a container from it
docker ps # list running containersRemember
Image = template. Container = running instance.