Back to Blog
Lesson 35 of the Docker: Containers & Your First Image course
DevOpsAugust 22, 20264 min read

Volume Drivers and External Storage: A Docker Guide

Learn to extend Docker persistence beyond the local host. Master volume drivers, mount external storage, and implement essential backup strategies.

DockerDevOpsPersistenceStorageBackups
Closeup of an external hard drive connected to a laptop with a USB cable on a desk.

Previously in this course, we covered Introduction to Volumes: Mastering Docker Data Persistence, where we established how to keep data alive after a container is destroyed using local host storage. In this lesson, we level up: we move beyond the limitations of a single host by exploring volume drivers and external storage, which are essential for production-grade, distributed architectures.

What are Volume Drivers?

At its core, a Docker volume driver is a plugin that tells the Docker engine how to handle data storage. By default, Docker uses the local driver, which stores data on the physical disk of the machine running the engine.

However, in production environments, you often need storage that isn't tied to a single node—like cloud-provided block storage (AWS EBS, Azure Managed Disks) or shared network file systems (NFS). Volume drivers abstract these complex storage backends into a standard interface that your containers can consume.

Mounting External Volumes

When you use an external volume driver, you aren't just creating a local directory; you are instructing a provider to provision or attach a remote resource.

Consider a scenario where you use an NFS (Network File System) server to share data across multiple containers on different hosts. You would first install the appropriate driver (often via a containerized plugin), then create a volume specifying that driver:

Bash
# Install the NFS driver plugin (example)
docker plugin install vieux/sshfs

# Create a volume using the driver
docker volume create \
  --driver vieux/sshfs \
  --opt sshcmd=user@remote_host:/path/to/data \
  --opt password=remote_password \
  my_external_volume

Once created, you attach this to your container just like any other volume:

Bash
docker run -d \
  --name web-app \
  -v my_external_volume:/app/data \
  nginx

The container now treats the remote network share as if it were a local directory.

Backup Strategies for Persistence

Storing data is only half the battle; ensuring it can be recovered is the other. Because volumes reside outside the container's lifecycle, they are easier to back up than the container itself.

  1. The "Sidecar" Backup Pattern: You can run a temporary container that mounts the target volume and a backup directory, then runs an archive command (like tar or rsync).
  2. Snapshot-based Backups: If using cloud storage drivers (like AWS EBS), you should leverage the provider's native snapshot API. This is usually faster and more reliable than copying files manually.
  3. Automated Tools: For more complex environments, specialized tools like Docker data persistence: Backing up volumes with Restic and Cron provide point-in-time recovery and encryption.

Hands-on Exercise: Inspecting Your Drivers

Before jumping into cloud-based drivers, let's see what is currently available on your machine.

  1. List the installed volume drivers: docker info | grep -A 5 "Volume". You should see local listed as the default.
  2. Create a dummy volume using the default driver.
  3. Inspect the volume details: docker volume inspect <volume_name>. Note the Mountpoint field; this is where the local driver points on your host.

Common Pitfalls

  • Ignoring Latency: Network-attached storage (like NFS or cloud block storage) introduces latency. Databases, in particular, may struggle if the storage driver isn't tuned for high I/O.
  • Tight Coupling: Avoid hardcoding specific host paths in your application logic. Always use volumes to abstract the mount point.
  • Orphaned Volumes: When testing with drivers, remember that creating a volume is an active resource request. If you delete a container, the volume persists—use docker volume prune to clean up unused volumes during development.

FAQ

Can I move a volume between different hosts? If you use a network-based driver (like NFS or cloud storage), yes. The data is stored remotely, so any host with the correct driver and permissions can mount it.

Are volume drivers secure? Drivers handle authentication (like SSH keys or API tokens). Always manage these credentials using secrets management rather than hardcoding them in your docker run commands.

Recap

We've moved beyond local storage by using volume drivers to bridge Docker containers with remote storage backends. We also touched on the importance of backup strategies—an essential step for any production project. By now, you should understand that persistence isn't just about keeping files—it's about managing data availability across your infrastructure.

Up next: We will look at Image Scanning for Vulnerabilities to ensure your container images are as secure as your storage strategy.

Similar Posts