Docker Images and Containers
What is the difference between a Docker image and a container? What happens when you run an image?
what they're testing: The interviewer is checking whether you can distinguish a deployable artifact from its runtime instances and reason about their state and lifecycle.
An image is the reusable package; a container is what Docker creates from that package to run a workload. The image contains the files, libraries, and default configuration the workload needs. Its filesystem is built from immutable, read-only layers. docker run myapp:1.0 pulls the image if needed, creates a new container, applies runtime options, and starts the image's default process or a command you supplied.
The new container gets its own thin writable layer. Two containers created from the same image can therefore change files independently without changing the image or each other. Rebuilding or pulling a newer image does not update an existing container. To deploy that image, replace the old container with one created from it.
A "running instance" is useful shorthand, but a container can also be created or stopped. Docker can start a stopped container later with its configuration and writable layer intact. Removing the container removes that layer, while the underlying image remains. Put data that must outlive the container in a volume, bind mount, or external store.
Where people slip
the tempting wrong answer, and what's actually true
An image is just a stopped container.
An image is an immutable layered package, while a stopped container is a separate object with its own configuration and writable layer.
A container is always running.
A container can be created without starting and can remain after its process stops.
Changing files inside a container updates the image.
Container filesystem changes go into that container's writable layer and leave the image unchanged.
Deleting a container deletes its image and all persisted data.
Removing a container deletes its writable layer, not the image. Named volumes remain until separately removed, and bind-mounted data stays on the host.
If they push further
What happens to existing containers when you build or pull a newer image?
Nothing changes in those containers because they were created from the earlier image. Create replacement containers from the new image to deploy the update.
How should a container persist database or uploaded data?
Mount a Docker volume or use an external data store so the data is not tied to the container's writable layer. A volume can outlive the container that used it.
Can several containers use the same image at once?
Yes. They share the image's read-only layers, while each container receives its own writable layer and runtime configuration.
Sources
- Docker Docs: What is an image? ↗docs.docker.com
- Docker Docs: What is a container? ↗docs.docker.com
- Docker Docs: Storage drivers ↗docs.docker.com
- Docker Docs: Volumes ↗docs.docker.com
Now answer it yourself.
Reading a strong answer is easy. Producing one under pressure is the skill the interview tests. Gapmap grades your answer against the same bar an interviewer would.
beta
The interviewer part is in the works.
The diagnostic, personal maps, and AI mock interviews are being finished right now. The notes stay free either way. Leave an email and you'll get the first-cohort invite, plus a month of Pro when it opens.