Docker Compose — Volumes in Compose
Welcome to Chapter 5 — Volumes. Data persistence is critical for databases, file uploads, and application state. This chapter covers every way to manage data with Docker Compose.
Topics in This Chapter
| # | Topic | Description |
|---|---|---|
| 1 | Named Volumes | Persistent Docker-managed volumes |
| 2 | Bind Mounts in Compose | Mounting host directories into containers |
| 3 | Volume Syntax | Short form vs long form syntax |
| 4 | Sharing Volumes | Sharing data between services |
| 5 | Volume Lifecycle | Creating, inspecting, and removing volumes |
Why Volumes Matter
Without volumes: With volumes:
┌─────────────┐ ┌─────────────┐
│ Container │ │ Container │
│ ┌───────┐ │ │ ┌───────┐ │
│ │ Data │ │ │ │ Data │──┼──→ Volume
│ └───────┘ │ │ └───────┘ │ (persists)
└─────────────┘ └─────────────┘
docker compose down docker compose down
→ Data LOST ❌ → Data SAFE ✅