Docker Storage Architecture Overview
What you'll learn: How Docker manages data on disk using layers, sharing, and copy-on-write to make containers fast and efficient.
The Layered Storage System
Docker doesn't create a complete filesystem copy for every container. Instead, it uses a layered approach like a stack of transparent sheets. Each instruction in your Dockerfile (RUN, COPY, etc.) creates a new read-only layer. When you launch a container, Docker adds a thin writable layer on top of the image layers.
Think of it like building with LEGO base plates: multiple containers can share the same foundation pieces (base image layers), but each adds its own unique top layer for changes.
Copy-on-Write Mechanism
When a container needs to modify a file from a lower layer, Docker doesn't change the original. Instead, it copies the file up to the writable layer and modifies it there. The original layer remains unchanged.
This is why:
- Multiple containers from the same image use minimal extra disk space
- Image layers stay immutable and cacheable
- Containers start almost instantly (no full filesystem copy needed)
Layer Sharing in Action
If you run 10 containers from the same Ubuntu base image, you don't store 10 copies of Ubuntu. All containers share those base layers on disk. Only their unique writable layers consume additional space.
The storage driver (overlay2, aufs, etc.) manages this union of layers, presenting them as a single unified filesystem to each container while physically storing shared layers just once.
Key Takeaway: Docker's layered storage with copy-on-write lets many containers share base image layers efficiently, making containers lightweight and fast to start while keeping images immutable and reusable.