Docker

Docker Volume CLI

Docker volume commands for persistent data management.

27 commands
Windows MacOS Linux
#storage #containers

Volume Management

List all volumes
docker volume ls
Create a named volume
docker volume create mydata
Remove a volume
docker volume rm mydata
Remove all unused volumes
docker volume prune
Remove all volumes not used by containers
docker volume prune -a

Usage

Mount named volume to container
docker run -v mydata:/app/data nginx
Bind mount host directory
docker run -v /host/path:/app/data nginx
Mount volume as read-only
docker run -v mydata:/app/data:ro nginx
Mount with explicit syntax
docker run --mount source=mydata,target=/app/data nginx
Mount tmpfs for temporary data
docker run --tmpfs /app/tmp nginx
Mount multiple volumes
docker run -v mydata:/data -v logs:/logs nginx

Backup & Restore

Backup volume to tar
docker run --rm -v mydata:/data -v $(pwd):/backup busybox tar czf /backup/data.tar.gz -C /data .
Restore volume from tar
docker run --rm -v mydata:/data -v $(pwd):/backup busybox tar xzf /backup/data.tar.gz -C /data
Copy between volumes
docker run --rm -v mydata:/from -v newdata:/to busybox sh -c 'cp -a /from/. /to/'

Drivers

Create with local driver
docker volume create --driver local mydata
Create NFS volume
docker volume create --driver local --opt type=nfs --opt o=addr=192.168.1.1,rw --opt device=:/path mydata
Create tmpfs volume
docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m mytmp
Create volume with label
docker volume create --label env=prod mydata

Inspection

Show volume details and mount point
docker volume inspect mydata
Show container volume mounts
docker inspect --format '{{json .Mounts}}' mycontainer
docker volume ls --filter driver=local # Filter volumes by driver
Filter volumes by label
docker volume ls --filter label=env=prod
List volume names only
docker volume ls -q
Show disk usage by volumes
docker system df -v

Quick Commands

List all Docker volumes
docker volume ls
Create a new named Docker volume
docker volume create <name>
Display detailed information about a volume
docker volume inspect <name>