arrow_back
Back

Docker storage: volumes, bind mounts, and persistence

Andrew Dorokhov Andrew Dorokhov schedule 2 min read
menu_book Table of Contents

Data categories

  • Non-persistent
    • Ephemeral data.
    • Every container has it (the writable top layer of the image filesystem).
    • Tied to the container lifecycle.
  • Persistent
    • Volumes.
    • Decoupled from individual containers.

Local (non-persistent) storage

  • All containers use local storage by default.
  • Storage locations:
    • Linux: /var/lib/docker/<STORAGE-DRIVER>/
    • Windows: c:\ProgramData\Docker\windowsfilter\
  • Common drivers by distro:
    • RHEL: overlay2
    • Ubuntu: overlay2 or aufs
    • SUSE: btrfs
    • Windows: its own driver

See Storage drivers for UnionFS driver details.

Bind mounts

Bind mounts have existed since early Docker releases. They are more limited than volumes.

A bind mount mounts a file or directory from the host into the container.

When to use bind mounts

Use them when you need to mount configuration files into a container.

Volumes

Volumes use a directory under Docker’s storage path on the host. Docker manages that directory.

  • Use a volume for persistent data:
    1. Create the volume.
    2. Create your container.
  • Mounted to a path inside the container.
  • Data is written to the volume.
  • Deleting a container does not delete the volume.
  • First-class objects with their own API and subcommands.
  • Default local driver creates storage on the Docker host.
  • Third-party drivers:
    • Block storage (high performance): Amazon EBS, OpenStack Cinder.
    • File storage: NetApp FAS, Azure File Storage, Amazon EFS.
    • Object storage (large, rarely changed files): Amazon S3, Ceph, MinIO, OpenStack Swift.
  • Storage locations:
    • Linux: /var/lib/docker/volumes/
    • Windows: c:\ProgramData\Docker\volumes
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Docker storage drivers: AUFS, Overlay, devicemapper, BTRFS, ZFS

arrow_forward