docker volume command
docker volumeThe command is used to manage Docker volumes. Volumes are file systems used for persisting data, which can be shared and reused between containers. By using volumes, data can still be retained even when containers are stopped or deleted.
Commondocker volumeCommand
docker volume lsList all volumesdocker volume inspectView detailed information about a volumedocker volume createCreate a new volumedocker volume rmDelete one or more volumesdocker volume pruneDelete unused volumes
docker volume lsCommand
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
--driverSpecify the volume driver (default islocal)。--labelAdd labels to a volume.-o, --optSpecify driver options for a 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
Delete unused volumes.
docker volume prune
Use Case
- Persistent data: Volumes are used to persist data, and even if containers are deleted, the data remains retained.
- Shared data: Volumes can share data between multiple containers.
- Backup and restore: Volumes can be used to back up and restore container data.
- Separate data and applications: Volumes separate data from applications, making management and migration easier.
docker volumeThe 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 various data management needs.
other extensions