Skip to content
tezvyn:

How do Docker images and containers differ and relate?

Source: phoenixnap.comEasyHow cards are made

How do Docker images and containers differ and relate?

This tests your grasp of the immutable template versus mutable runtime boundary. A good answer: an image is a read-only layered template with code and dependencies; a container is a runnable instance with a writable layer on top.

What's really being asked

This question probes whether you understand the fundamental abstraction in Docker: the separation between a static artifact and a running process. Interviewers want to see that you know an image is not just a file but a layered, read-only template, and that a container is not a full VM but a process-level runtime that reuses those layers while adding a thin writable layer on top.

The full answer

Four things in order. First, define a Docker image as an immutable, read-only file that packages source code, libraries, dependencies, and tools, typically built from a Dockerfile using docker build. Second, explain that images are layered, starting from a base image and stacking modifications, which makes them reusable and efficient. Third, define a container as a runnable instance of an image that adds a writable container layer on top of the read-only image layers, allowing runtime changes without altering the original image. Fourth, describe the relationship: containers are created from images, multiple containers can share the same image, and changes in the container layer can be committed back into a new image using docker commit.

The mistakes people make

Treating images and containers as interchangeable. Saying an image is just a tarball or zip file without mentioning layers or immutability. Claiming a container is a mini-VM rather than an isolated process using the host kernel. Forgetting that the writable layer is ephemeral by default and disappears when the container is removed unless committed or volumes are used.

What usually comes next

How does layer caching speed up builds? What happens to the writable layer when the container stops? How do multi-stage builds relate to image size? Can two containers modify the same image layer? What is the difference between docker commit and building from a Dockerfile?

A concrete example

Imagine the official Nginx image. It consists of a base Alpine Linux layer plus an additional layer containing the Nginx installation. When you run docker run nginx, Docker creates a container that mounts the read-only image layers and adds a writable layer on top. If you edit the default index.html inside the container, that change lives only in the writable layer. If you run docker commit on that container, Docker converts the writable layer into a new read-only image layer, producing a new image that includes your modified index.html.

Interview question

When you run a container from an image, how does Docker handle the image layers and runtime file changes?

  • a.It keeps the image layers read-only and adds a writable layer on top for runtime changes.Correct
  • b.It converts the image into a virtual disk that the container boots as an independent mini-VM.
  • c.It copies all image layers into the container so changes do not affect the original image.
  • d.It merges runtime changes back into the image layers so all containers see the updates.
Why?

A container mounts the image's read-only layers and adds a writable layer on top, allowing runtime changes without altering the original image. Option B is wrong because containers are isolated processes that share the host kernel, not mini-VMs that boot their own kernels.

Just read this? Test yourself on what you have been reading.

Read the original → phoenixnap.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on docker — each one lists the topics its interview covers.

See open roles