What is overlay2 storage driver and how does it work?
Why Interviewers Ask This
Interviewers ask this to evaluate whether you have the depth of knowledge needed to mentor others and lead technical decisions. The expected answer goes beyond definitions into practical implications and real-world consequences.
Answer
overlay2 is Docker's default and recommended storage driver on Linux (for kernel 4.0+). It implements Docker's layered filesystem using the Linux OverlayFS (overlay filesystem) kernel feature. How it works: OverlayFS merges multiple directories (layers) into a unified view. It has three components: (1) lowerdir — read-only image layers (multiple layers stacked); (2) upperdir — writable container layer; (3) merged — the unified view the container sees. When a container reads a file: OverlayFS looks in upperdir first, then lowerdir. When a container writes/modifies a file that exists only in a read-only lowerdir layer, OverlayFS performs a copy-on-write (CoW): copies the entire file to upperdir, then modifies it there. When a container deletes a lower layer file, OverlayFS creates a "whiteout" file in upperdir to mask it. Storage on disk: /var/lib/docker/overlay2/ — each layer has its own directory. Image layers are shared on disk — multiple containers using the same image share the same lower layers; only the upperdir (container layer) is unique per container. Other storage drivers: aufs (legacy), btrfs, zfs, devicemapper (legacy). Overlay2 is recommended for most production systems.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Docker answers easy to follow.
Previous
What are Linux namespaces and cgroups, and how do they enable containers?
Next
What is Docker Buildx and multi-platform builds?
More Docker Questions
View all →- Advanced What is containerd and how does it relate to Docker?
- Advanced What are Linux namespaces and cgroups, and how do they enable containers?
- Advanced What is Docker Buildx and multi-platform builds?
- Advanced What is Docker networking at a deep level (iptables, veth pairs)?
- Advanced What is the difference between Docker Swarm services and Docker Compose services?