Video in progress
What is the difference between a Docker image and a container?
An image is an immutable template: an OS layer, a JRE, your jar. A container is a live process started from that image, with its own writable layer on top.
📖 Answer
A simple analogy: an image is a class, a container is an object created from it. You can start ten containers from one image.
docker build -t shop-api:1.4.0 . # build the image
docker run -d --name api1 shop-api:1.4.0
docker run -d --name api2 shop-api:1.4.0 # a second container from the same image
docker ps # running containers
docker images # local images
An image is made of read-only layers. When a container starts, a thin writable layer is added on top: a file created inside the container lives only in that layer. When the container is removed (docker rm), that layer goes with it, while the image stays where it was.
Interviewers often see this mistake: "I logged into the container and fixed the file." That fix disappears on the next deploy. The change has to go into the image, which means the Dockerfile.
Sign up to mark studied questions and save your progress.