docker storage volumes

Core Idea

Two driver families keep container data straight: storage drivers manage the container’s read-write filesystem layers, volume drivers manage named volumes that outlive containers.

  • Storage drivers: what they are, the types Docker offers, and their limitations.
  • Volume drivers: the mechanism for named volumes, with the common drivers listed.
  • The split matters because only volumes are meant for data you keep.

Storage drivers | Docker Docs
04. Volumes
09. Volume & persistent data

Storage Drivers

Docker uses storage drivers to store image layers, and to store data in the writable layer of a container.

Tip

To Selection of the storage drivers depends on the underlying OS. Docker will choose the best storage driver available automatically based on the operating system.

Types of Docker Storage Drivers

Docker supports multiple storage drivers, with the most commonly used being:

  1. OverlayFS (overlay2) – Recommended for most Linux distributions

    • Uses a union filesystem to merge multiple layers.
    • Efficient and faster compared to older drivers like AUFS.
    • Default for many Linux distributions.
  2. AUFS (Advanced Multi-Layered Unification Filesystem)

    • Previously widely used but now deprecated.
    • Allows multiple layers to be stacked.
  3. Devicemapper (Block-level storage)

    • Uses block devices instead of filesystems.
    • Better for high-performance workloads but more complex to configure.
  4. Btrfs (Copy-on-Write filesystem)

    • Provides snapshot and cloning capabilities.
    • Best suited when running Docker on a Btrfs-supported system.
  5. ZFS (Advanced storage management)

    • Uses a pooled storage model.
    • Includes built-in compression, deduplication, and snapshots.
  6. VFS (Virtual Filesystem)

    • Used for debugging or special cases where Copy-on-Write isn’t needed.
    • Slow and inefficient but useful for certain testing environments.

Limitations of Storage Drivers

  • The writable layer is not persistent—any data stored inside a container is lost when the container is removed.
  • It is not ideal for database storage, where high-performance read/write operations are needed.

Docker Volume Drivers

Volumes | Docker Docs

While storage drivers manage the container’s filesystem, volume drivers are used for persistent storage that exists beyond the container’s lifecycle.
Default volume driver plugin is local

Common Volume Drivers

  1. local (default)

    • Uses the host machine’s filesystem to store data.
    • Works well for local setups but lacks features like replication.
    • The local volume plugin helps to create a volume on Docker host and store its data under the /var/lib/docker/volumes/ directory.
  2. nfs (Network File System)

    • Used for shared storage across multiple Docker hosts.
    • Useful for distributed applications.
  3. azurefile (Microsoft Azure)

    • Used for storing data in Azure File Storage.
    • Ideal for cloud-based workloads.
  4. amazon-efs (AWS Elastic File System)

    • Used for persistent storage on AWS.
    • Good for multi-container applications running on AWS.
  5. ceph, flocker, portworx, glusterfs (Third-party solutions)

    • Offer advanced features like high availability, redundancy, and performance tuning.
docker run -it --name mysql --volume-driver rexray/ebs --mount src=ebs-vol,target=/var/lib/mysql mysql