docker volume Command
docker volume The command is used to manage Docker volumes. A volume is a filesystem used to persist data and can be shared and reused among containers. By using volumes, data is retained even when a container is stopped or deleted.
Common docker volume Command
docker volume ls: List all volumesdocker volume inspect: View detailed information about a volumedocker volume create: Create a new volumedocker volume rm: Delete one or more volumesdocker volume prune: Remove unused volumes
docker volume ls Command
List all volumes.
docker volume ls
Output:
DRIVER VOLUME NAME
local my_volume
local another_volume
docker volume inspect command
View detailed information about a specified volume.
docker volume inspect my_volume
Output:
[
{
"CreatedAt": "2024-07-23T00:00:00Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/my_volume/_data",
"Name": "my_volume",
"Options": {},
"Scope": "local"
}
]
docker volume create command
Create a new volume.
docker volume create my_volume
Common parameters
--driver: Specify the volume driver (default islocal)。--label: Add a label to the volume.-o, --opt: Specify driver options for the volume.
Example:
docker volume create --name my_volume --label project=my_project
docker volume rm command
Delete one or more volumes.
docker volume rm my_volume
Delete multiple volumes:
docker volume rm volume1 volume2
docker volume prune command
Remove unused volumes.
docker volume prune
Use Cases
- Persisting data: Volumes are used to persist data; even if a container is deleted, the data is retained.
- Sharing data: Volumes can share data among multiple containers.
- Backup and restore: Volumes can be used to back up and restore container data.
- Separating data and applications: Volumes separate data from applications, making them easier to manage and migrate.
docker volume This command set provides powerful data management capabilities, allowing users to create, configure, and manage Docker volumes. By using these commands, users can achieve data persistence, sharing, and backup, meeting a variety of data management needs.
Docker Command Reference