Why Volumes?
- Container filesystems are ephemeral
- Volumes persist data beyond container lifecycle
- Share data between containers
Types of Mounts
- Volumes - Docker-managed storage
- Bind Mounts - Host filesystem paths
- tmpfs - Memory-only storage
Named Volumes
bash
1# Create volume
2docker volume create mydata
3
4# Use volume
5docker run -v mydata:/app/data nginx
6
7# List volumes
8docker volume ls
9
10# Inspect volume
11docker volume inspect mydata
12
13# Remove volume
14docker volume rm mydataBind Mounts
bash
1# Mount current directory
2docker run -v $(pwd):/app myapp
3
4# Mount specific path
5docker run -v /host/path:/container/path nginxVolume vs Bind Mount
| Feature | Volume | Bind Mount |
|---|---|---|
| Managed by | Docker | Host |
| Location | /var/lib/docker/volumes | Anywhere |
| Best for | Persistence | Development |
