“docker volume” Command Examples

The “docker volume” command is a part of Docker’s functionality that allows you to manage Docker volumes. Docker volumes are a feature that enables data persistence and sharing between containers and between containers and the host machine.

When you use the “docker volume” command, you can perform various operations related to Docker volumes. Here are some key commands and their explanations:

  • docker volume create“: This command creates a new Docker volume. When you create a volume, Docker creates a directory on the host machine and associates it with the volume. Containers can then mount this volume to access and store data persistently.
  • docker volume ls“: This command lists all the Docker volumes present on your system. It provides information such as the volume name and the driver used for the volume. This can help you keep track of existing volumes and their usage.
  • docker volume inspect“: With this command, you can obtain detailed information about a specific Docker volume. It provides information like the volume name, driver, mount point on the host machine, and any labels or metadata associated with the volume.
  • docker volume rm“: This command allows you to remove one or more Docker volumes that are no longer needed. When you remove a volume, Docker deletes the associated directory and any data stored within it. Make sure to back up any important data before removing a volume, as the data will be permanently lost.
  • docker volume prune“: By executing this command, you can remove all unused Docker volumes. Unused volumes are those that are not currently associated with any containers. It is a useful command for cleaning up and reclaiming disk space.
  • docker volume inspect“: This subcommand provides detailed information about a specific Docker volume. It includes metadata such as the volume name, driver, and mount point on the host machine. This information can be useful for troubleshooting or understanding the properties of a volume.

Docker volumes are essential for persisting and sharing data between containers and with the host machine. They enable data to survive container restarts or removals, ensuring data durability. With the “docker volume” command, you can create, list, inspect, and remove volumes, allowing you to manage data persistence effectively within your Docker environment.

docker volume Command Examples

1. Create a volume:

# docker volume create volume_name

2. Create a volume with a specific label:

# docker volume create --label label volume_name

3. Create a tmpfs volume a size of 100 MiB and an uid of 1000:

# docker volume create --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000 volume_name

4. List all volumes:

# docker volume ls

5. Remove a volume:

# docker volume rm volume_name

6. Display information about a volume:

# docker volume inspect volume_name

8. Remove all unused local volumes:

# docker volume prune

9. Display help for a subcommand:

# docker volume subcommand --help
Related Post