How containers/storage works
Project type and purpose
• This is a Go-based library (called “storage”) with a secondary CLI wrapper (containers-storage) for managing container layers, images, and containers on disk.
• Primary use case: provide programmatic APIs for creating, querying, and modifying copy-on-write filesystem layers, plus a command-line interface for scripting and manual operations.
File-structure analysis
• Top-level
• cmd/containers-storage: CLI entrypoint, one file per CLI command, calls into library
• pkg/, internal/: Go packages implementing core functionality (archive, chunked, config, drivers, etc.)
• drivers/: pluggable filesystem drivers (overlay, aufs, btrfs, vfs, zfs, windows)
• types/: type definitions (IDs, options, error handling)
• check.go, store.go: top-level initializers
• tests/: Bash “bats” integration tests for CLI behavior
• Build & CI
• Makefile, .cirrus.yml, contrib/cirrus: build/test scripts
• vendor/: vendored dependencies
README insights
• Describes three managed entities: layers (CoW filesystems), images (top-layer refs + metadata), containers (read-write children with config)
• Mentions optional VM test environment via Vagrant+libvirt
Main components
a. CLI layer
• containers-storage binary (cmd/containers-storage)
b. Core library
• Storage Manager (store.go)
• Metadata store (in-memory/cache + on-disk bookkeeping)
• Big-data store (named chunked files for images/containers)
c. Subsystems
• Drivers subsystem (drivers/*)
• Archive subsystem (pkg/archive, pkg/chrootarchive)
• Chunking & compression (pkg/chunked)
• Configuration & options (pkg/config, internal/opts, types)
• File and filesystem utilities (pkg/fileutils, pkg/fsutils, pkg/mount, pkg/loopback, pkg/unshare)
d. Host environment
• OS kernel interfaces (mount, chroot, loopback, syscalls)
• Optional Vagrant + libvirt VM layer for CI tests
Relationships & data flows
• CLI → Storage Manager API calls → Core library
• Storage Manager → Drivers (via driver.Register) → Kernel
• Storage Manager → Archive/Chunked subsystems → Data files on disk
• Metadata cache ↔ On-disk metadata files
• Big-data read/write ↔ Named files on disk
• Tests & CI runners drive the CLI component
Architectural patterns & principles
• Layered architecture: CLI, API core, subsystem packages, OS drivers
• Plugin pattern for filesystem drivers (registerable drivers in drivers/register)
• Separation of concerns: distinct packages for archiving, chunking, config, and system calls
• Dependency injection: core components accept driver interfaces, config objects