docker volume command

Docker command reference


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

  1. docker volume lsList all volumes
  2. docker volume inspectView detailed information about a volume
  3. docker volume createCreate a new volume
  4. docker volume rmDelete one or more volumes
  5. docker 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.


Docker command reference

other extensions