What is a Docker image, and how do layers and immutability work?
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
An image is an immutable, read-only template packaging everything a container needs — binaries, libraries, config. It is a stack of layers, one per Dockerfile instruction; rebuilding reuses unchanged layers and only rebuilds what changed, which docker image history reveals.
Detailed explanation
Build from another image and customize: a Python app starts FROM the Python image and adds layers for dependencies and code, so you focus on your app, not the runtime. Two principles govern everything: images cannot be modified after creation (you only create new images or add layers on top), and each layer is a set of filesystem changes (add/remove/modify). That layering is what makes images small and fast versus other virtualization — change the Dockerfile and only changed layers rebuild. Hands-on proof from the docs: docker pull docker/welcome-to-docker downloads ~8 layers line by line; docker image ls shows the 29.7 MB uncompressed size; docker image history docker/welcome-to-docker lists every layer with its size and creating command (COPY app build, CMD nginx, EXPOSE 80, ENV, base Alpine layers). Docker Hub reinforces reuse with Official Images (Redis, Memcached, Node) as trusted starting points.
Official docs:Docker docs: What is an image?
Example
docker pull docker/welcome-to-docker
# ... one line per layer downloaded
docker image ls
# REPOSITORY TAG SIZE
# docker/welcome-to-docker latest 29.7MB
docker image history docker/welcome-to-docker
# IMAGE CREATED CREATED BY SIZE
# 648f93… 4mo ago COPY /app/build → nginx html 1.6MB
# <miss…> 5mo ago CMD ["nginx" "-g" ...] 0BInterview tip
Lead with 'immutable stack of filesystem diffs', then cite image history as how you inspect it — naming a real command beats reciting theory.
Common mistakes
- Saying you edit an image in place instead of adding layers.
- Confusing image size (uncompressed) with download size.