Course contentsShow
← Cloud and Infrastructure
Lesson 1035 of 2,98920. Docker in DepthFree lesson

Introduction to Docker Volumes

Learn Docker volumes as the preferred mechanism for persisting data generated and used by containers.

Introduction to Docker Volumes

You'll learn: Why Docker volumes are the recommended way to persist data that containers create or use, and how they differ from storing data inside containers.

The Problem with Container Storage

Remember from the previous lesson that containers have a writable layer for temporary data. Here's the catch: when a container is deleted, all data in that writable layer vanishes with it. This is fine for logs or cache, but terrible for databases, user uploads, or any data you need to keep.

What Are Docker Volumes?

Docker volumes are storage mechanisms that exist outside the container's filesystem but can be mounted into containers. Think of them like external hard drives you can plug into different computers—the drive persists even when you shut down the computer.

Volumes are managed entirely by Docker and stored in a special location on the host system (typically /var/lib/docker/volumes/ on Linux). The key advantage: volumes survive container deletion, can be shared between containers, and are more performant than other persistence options.

Why Volumes Are Preferred

Unlike storing data in the container's writable layer or using bind mounts (mounting host directories), volumes offer:

  • Decoupling: Data lives independently of container lifecycle
  • Portability: Docker manages the storage location
  • Performance: Optimized I/O, especially on non-Linux hosts
  • Safety: Easier to back up and migrate
  • Sharing: Multiple containers can safely use the same volume

Key Takeaway: Docker volumes are purpose-built storage units managed by Docker that persist data beyond container lifetimes—use them whenever your container needs to remember something after it restarts or gets replaced.