docker volume
The docker volume command is used to manage Docker volumes. Volumes are used to persist data generated by and used by Docker containers. This command provides various subcommands to create, inspect, list, and remove volumes.
Basic Syntax
Subcommands and Options
create: Create a new volume.
docker volume create [OPTIONS] VOLUMEOptions:
-d, --driver: Specify volume driver name (default is
local).docker volume create -d local myvolume-o, --opt: Set driver-specific options.
docker volume create -o type=tmpfs -o device=tmpfs myvolume
inspect: Display detailed information on one or more volumes.
docker volume inspect VOLUMEls: List all volumes.
docker volume lsrm: Remove one or more volumes.
docker volume rm VOLUMEprune: Remove all unused local volumes.
docker volume prune
Examples
Creating a Volume
docker volume create myvolumeThis command creates a volume named
myvolumewith the defaultlocaldriver.Creating a Volume with Specific Options
docker volume create -o type=tmpfs -o device=tmpfs myvolumeThis command creates a volume named
myvolumewith the specified options.Listing All Volumes
docker volume lsThis command lists all the volumes available on the Docker host.
Inspecting a Volume
docker volume inspect myvolumeThis command displays detailed information about the volume named
myvolume.Removing a Volume
docker volume rm myvolumeThis command removes the volume named
myvolume.Pruning Unused Volumes
docker volume pruneThis command removes all unused local volumes.
Conclusion
The docker volume command is essential for managing Docker volumes. Understanding its subcommands and options allows you to effectively create, inspect, list, and remove volumes, as well as prune unused volumes.