Open-Source Wikis

/

Moby

/

Primitives

/

Layer

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

  • Layer is the read-only image layer.
  • RWLayer is 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:

  1. Verifies the digest matches the descriptor.
  2. Streams the tarball through the graphdriver's ApplyDiff.
  3. Records the diffID/chainID in the layer DB.
  4. 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

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Layer – Moby wiki | Factory