moby/moby
Layer
Definition
A layer is a content-addressed filesystem diff produced by a graphdriver. Layers chain: each layer has a parent (or none, for the base). The daemon refers to a layer by:
- DiffID — SHA-256 of the uncompressed tarball of the diff.
- ChainID — SHA-256 of the chain so far; computed as
sha256(parent_chain + " " + diff_id). - CacheID — the graphdriver-internal identifier (typically a UUID).
The legacy abstraction lives in daemon/internal/layer/. When the daemon runs with the containerd-backed image store, layers are managed by containerd snapshotters and this package is mostly bypassed.
Layout
| File | Role |
|---|---|
layer.go |
Layer, RWLayer, MountID interfaces and constants. |
layer_store.go |
Store impl: tracks roLayers + mounts, persists metadata. |
migration.go |
One-time upgrade hook for older daemon versions. |
mounted_layer.go |
Mount tracking for RW layers. |
empty.go |
The well-known empty layer (used as the base of scratch). |
| Per-OS files | Linux/Windows specific layer plumbing. |
Read-only vs read-write
Layeris the read-only image layer.RWLayeris a per-container writable scratch space stacked on top of an image's chain.
Daemon.Container.RWLayer (in daemon/container/container.go) holds the active RW layer for a running container.
Metadata
layer_store.go keeps layer metadata in <data-root>/image/<graph-driver>/layerdb/ — JSON files with the diffID, chainID, parent, size, and creation timestamp. The graphdriver only stores raw filesystem trees.
Distribution interplay
When a layer is pulled from a registry (Distribution), the daemon:
- Verifies the digest matches the descriptor.
- Streams the tarball through the graphdriver's
ApplyDiff. - Records the diffID/chainID in the layer DB.
- The image store then becomes able to refer to the chain.
When a container exits, its RW layer is either kept (if --rm is not set) or removed via RWLayer.Release.
See also
- Image management for how layers fit into images.
- Graphdrivers for the actual filesystem implementation.
- Distribution for fetching layers from registries.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.