Throughout this blog post, we will explore how to manage volumes with the Docker CLI. When you use Docker for development and testing purposes, it can be helpful to have a persistent volume so that you don’t lose your work when the container is destroyed or stopped.

This type of setup is also great to share data between containers running on different hosts in a cluster.

There are two types of volumes: local and remote. Local volumes are created within the same host as the Docker daemon, whereas remote volumes are stored on an external storage device somewhere else on your network, where they can be mounted into any container using their pathname.

We have written a few posts about how to create volumes with Docker, and today we will show you how to manage volumes using all the CLI commands.

Create a Volume

The first command will create a new volume on the host.

docker volume volumename

View Volumes

To view all the volumes on the host, use the ls command.

docker volume ls

To inspect a specific volume and view the full path of the volume, use the following command.

docker volume inspect volumename

Delete Unused Volumes

To delete all the unused volumes on the host, use the prune command. Be careful with this command, as it will delete all the unused volumes.


docker volume prune

Delete Specific Volume

To delete a specific volume, use the command below.

docker volume rm volume name


Posted

in

,

by