Docker · Containers in practice

What is the difference between an image and a container?

EasyimagescontainersimmutabilityUpdated Oct 2026
Quiz this track

Short answer

An image is an immutable, layered filesystem template. A container is a running instance of that image with a writable layer and its own process, network and mounts.

An image is built once and does not change. Each Dockerfile instruction produces a layer, and the image is identified by a digest derived from its content. A container adds a thin writable layer on top, so writes at runtime do not modify the image or affect other containers started from it.

sh
docker build -t api:1.0.0 .
docker run -d --name api-1 api:1.0.0
docker ps
docker exec api-1 sh -c "echo hello > /tmp/probe"
The write goes to the container layer. The image and any other container are unchanged.

Practical consequences

  • Rebuilding is how you change an image; you do not patch a running container
  • The writable layer is tied to the container and disappears with it
  • Data that must survive belongs in a volume, not the container layer
  • Many containers can run from the same image with different configuration

Image tags are mutable labels, but digests are immutable. Deploying by digest avoids the surprise of a tag moving under you, which is why production systems often pin digests.

A container is not a small image. It is a process plus the mounts and namespaces it was started with.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Where do writes made inside a running container go?
  2. 2Why is the writable layer a bad place for persistent data?
  3. 3What is the difference between an image tag and a digest?
  4. 4Can two containers share the same image safely?

Say it in the interview

An image is an immutable layered filesystem template, and a container is a running instance of it with an extra writable layer. Writes at runtime go to that layer, so they vanish when the container is removed and do not affect the image or other containers. That is why I keep persistent state in volumes and deploy images by immutable digest in production.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Docker mock interview and get scored feedback on depth, clarity and confidence.