Module 9 Lesson 1: Volume Drivers and Types
Master the data layer of Docker. Explore the different volume drivers and types, and learn how to choose the right storage strategy for your application's data.
Module 9 Lesson 1: Volume Drivers and Types
We know that Volumes are how we keep data alive. But not all volumes are created equal. Depending on where your app is running (on your laptop, a server, or the cloud), you need different Volume Drivers.
1. What is a Volume Driver?
A driver is the "Translator" between Docker and your physical storage.
local(Default): Saves files in a folder on your computer's hard drive.sshfs: Saves files on a remote server over SSH.aws-s3/azure-file: Saves files directly to cloud storage.
2. Types of Mounts (Recap & Deep Dive)
A. Named Volumes
docker run -v my-data:/app/data
- Docker creates a folder in a managed area (e.g.,
/var/lib/docker/volumes/). - Primary Use: Databases and internal app state.
B. Bind Mounts
docker run -v /home/user/my-code:/app
- Maps a specific host path to a container path.
- Primary Use: Development (hot-reloading).
C. Anonymous Volumes
docker run -v /app/data (Notice there is no name before the colon).
- Docker creates a random name (like
47d2f...). - Primary Use: Temporary storage that needs to persist even if the container is restarted but not necessarily saved forever.
D. tmpfs Mounts (Linux Only)
docker run --tmpfs /app/temp
- Saves files directly in RAM, not on disk.
- Primary Use: High-performance temporary files or sensitive data that must NEVER be written to the hard drive.
3. Choosing the Right Type
| Goal | Use... |
|---|---|
| Max Performance (DB) | Named Volume |
| Code Editing | Bind Mount |
| Sensitive/Temp Data | tmpfs |
| Cloud Portability | Volume Driver (e.g., RexRay) |
4. The "Volume Plugin" Power
Plugins allow you to connect Docker to enterprise storage systems (NetApp, Pure Storage, etc.). This allows a container on "Server 1" to be deleted and restarted on "Server 2" while automatically "Re-attaching" its data drive from the central storage.
Exercise: The Driver Check
- Run
docker info. Look for the "Storage Driver" and "Logging Driver" sections. What are they? - List your volumes:
docker volume ls. - Choose one and run
docker volume inspect <name>. What is the "Driver" listed there? (It should belocal). - Why would you use an Amazon S3 volume driver instead of just saving files to the local disk?
- What happens to the data in a
tmpfsmount if your computer loses power?
Summary
Volumes are the "Hard Drives" of the container world. By understanding the different drivers and mount types, you can design a data layer that is fast, secure, and moves seamlessly from your laptop to the cloud.
Next Lesson: Naming and organizing: Named vs. anonymous volumes.