What is the difference between a Docker image and a container?
What they are really testing: A basic screen-out. They want the image-as-template, container-as-running-instance distinction, and ideally the layered, immutable nature of images.
A real interview question
What is the difference between a Docker image and a container?
What most people say
drag me
“An image is the file and a container is when it runs.”
Roughly right but imprecise. It misses that images are immutable and layered, that many containers come from one image, and that the container writable layer is ephemeral, which matters for data.
The follow-ups they ask next
You made changes inside a running container and removed it; the changes are gone. Why?
They were written to the container ephemeral writable layer, which is discarded on removal. Persist data in a volume, or bake it into the image, instead of relying on the writable layer.
How can many containers run from one image efficiently?
They share the immutable image layers (copy-on-write); each adds only a small writable layer. So running 10 containers does not mean 10 full copies of the image.
What the interviewer is listening for
- Image=immutable template, container=running instance
- Knows the writable-layer/ephemeral point
- Mentions layers / many-from-one
What sinks the answer
- Cannot distinguish them clearly
- Thinks each container is a full copy
- Unaware writable layer is ephemeral
If you genuinely do not know
Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.
“An image is [an immutable, layered, read-only template built from a Dockerfile]. A container is [a running instance with a thin writable layer on top]. You run [many containers from one image, sharing its layers]. The writable layer is [ephemeral, lost on removal], so [persistent data needs a volume].”
Keep going with docker
Foundation
What is a container, and how is it different from a virtual machine?
Foundation
What is a Dockerfile, and what do the main instructions do?
Junior
How does the Docker build cache work, and how do you order a Dockerfile to use it well?
Junior
What is the difference between CMD and ENTRYPOINT, and what is the exec versus shell form?
Junior
How does container networking work in Docker, and how do containers talk to each other?
Junior
How do you persist data in Docker? Explain volumes versus bind mounts.
Knowing the answer is not the same as recalling it under pressure
Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.
Start free