Docker
/Advanced
Image Layers
Definition
The structural design of a Docker Image. Images are not single massive files; they are composed of a series of read-only layers stacked on top of each other. Each layer represents a single instruction from the Dockerfile.
Explain Like I'm New
Like a Photoshop file with layers. Layer 1: Install Linux. Layer 2: Install Python. Layer 3: Copy your code. If you change your code, Docker doesn't rebuild Linux and Python. It reuses those layers instantly, and only replaces Layer 3.
Real World Example
You pull a 1GB Node.js image. Later, you pull a different app that also relies on the exact same Node.js image. Docker realizes you already downloaded the 'Node.js Layer', so it only downloads the 2MB of new code layers, saving massive amounts of bandwidth.
Common Use Cases
- •Optimizing build speed
- •Saving disk space
Interview Questions
basic
- Does every command in a Dockerfile create a new Image Layer?
intermediate
- How does the 'Union File System' help Docker manage image layers?