Open-Source Wikis

/

containerd

/

Systems

/

Snapshotters

containerd/containerd

Snapshotters

Snapshotters produce the rootfs that a container will run in. Each snapshotter implements the Snapshotter interface in core/snapshots/snapshotter.go and is registered as a plugin of type io.containerd.snapshotter.v1.

Purpose

  • Take a stack of layer digests (provided by the unpack pipeline) and turn them into a writable rootfs mount.
  • Track parent/child snapshot relationships so that intermediate layers can be shared across containers.
  • Surface the resulting Mount records back to the runtime so it can mount the rootfs into the container's mount namespace.

Built-in snapshotters

Plugin ID Code path Notes
overlayfs plugins/snapshots/overlay/ Default on Linux. Uses kernel overlayfs.
btrfs plugins/snapshots/btrfs/ Subvolume-based; needs btrfs kernel module and headers.
devmapper plugins/snapshots/devmapper/ Thin-pool LVM snapshots. Linux-only. Built only with -tags devmapper.
native plugins/snapshots/native/ Plain copy on top of any filesystem. Slow but always works.
blockfile plugins/snapshots/blockfile/ Per-snapshot block-image files (good for VM-style sandboxes).
erofs plugins/snapshots/erofs/ Read-only EROFS layers + overlay upper.
windows plugins/snapshots/windows/ Windows container layers via hcsshim.
lcow plugins/snapshots/lcow/ Linux-containers-on-Windows.
zfs (separate go-build, registered when imported) ZFS dataset snapshots.

The interface

From core/snapshots/snapshotter.go, every implementation provides:

  • Stat(ctx, key) (Info, error)
  • Update(ctx, info, fieldpaths...) for label edits
  • Usage(ctx, key) (Usage, error)
  • Mounts(ctx, key) ([]mount.Mount, error) — the call that returns the kernel-level mount specs for the active snapshot
  • Prepare(ctx, key, parent, opts...) ([]mount.Mount, error) — the standard "give me a writable layer over parent" call
  • View(ctx, key, parent, opts...) ([]mount.Mount, error) — read-only sibling of Prepare
  • Commit(ctx, name, key, opts...) error — promote an active snapshot to a committed (immutable) one
  • Remove(ctx, key) error
  • Walk(ctx, fn, filters...) error — listing
  • Close() error

Lifecycle

stateDiagram-v2
    [*] --> Prepared: Prepare(key, parent)
    Prepared --> Committed: Commit(name, key)
    Prepared --> Removed: Remove(key)
    Committed --> Removed: Remove(name)
    Committed --> Prepared: Prepare(newKey, name)
    Removed --> [*]
  • An active snapshot has a writable upper layer; the snapshotter returns it from Prepare/View.
  • A committed snapshot is immutable. Layers extracted from images become committed snapshots; they're consumed as parents by container Prepare calls.
  • A container's working snapshot is Prepared at create time and Removed when the container is deleted.

Mount records

Snapshotters return mount.Mount records (defined in core/mount/mount.go):

type Mount struct {
    Type    string   // e.g. "overlay", "bind", "btrfs"
    Source  string
    Target  string
    Options []string
}

The runtime is responsible for actually performing the mount inside the container's namespace. See mount manager for the v2 abstraction that lets external mount handlers take over this step.

Metadata wrapping

Every snapshotter is wrapped by core/metadata/snapshotter.go before it's exposed to the rest of the daemon. The wrapper:

  • Stores labels and namespaces in bbolt so a single snapshotter binary can serve multiple namespaces.
  • Hooks into the GC walk so committed snapshots aren't pruned when a lease holds them.
  • Exposes the same interface, so callers don't know they're talking to a wrapper.

Snapshot service

The gRPC service Snapshots.<method> is implemented by plugins/services/snapshots/ and the wire format lives in api/services/snapshots/v1/.

Entry points for modification

  • New snapshotter: implement core/snapshots/snapshotter.go's interface and register a plugin under plugins/snapshots/<name>/. See plugins/snapshots/native/ for a minimal example (~150 LOC).
  • New label processing: edit the metadata wrapper in core/metadata/snapshotter.go.
  • New mount type: add a mount.Mount type and matching mount logic in core/mount/.

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

Snapshotters – containerd wiki | Factory