Open In App
Related Articles

Using CLI to Manage Docker Volumes

Improve Article
Improve
Save Article
Save
Like Article
Like

If you want to share files and directories among multiple Docker Containers, you can easily mount Docker Volumes to different Containers. However, managing such a large number of Docker Volumes becomes very difficult at times. In this article, we are going to discuss how to manage Docker Volumes by executing commands through the Docker Command Line Interface (CLI).

1. Creating Docker Volume

To create a Docker Volume, you can use the Volume Create command as shown below.

sudo docker volume create vol-demo

 Creating Docker Volume

2. Mounting Volume with a Container

After you have created a Volume, you can mount it with a Docker Container -v flag along with the Docker run command.

sudo docker run -it -v <volume-path-in-local-machine>:<dest-path-in-container> <image-name>

Mounting Volume with a Container

To verify if the volume has been successfully mounted or not, you can move to the destination directory inside the Container.

move to the destination directory

3. Listing all the Docker Volumes

You can list all your Docker Volumes using the Docker Volume ls command.

sudo docker volume ls

Listing all the Docker Volumes

4. Inspecting Docker Volumes

You can get the details of your Docker Volumes using the Volume Inspect Command.

sudo docker volume inspect <volume-name>

 Inspecting Docker Volumes

5. Removing specific Docker Volume

To remove a particular Docker Volume, you can specify the name in the Docker Volume rm command.

sudo docker volume rm <volume-name>

Removing specific Docker Volume

6. Removing all the Docker Volumes

To remove all the Docker volumes together, you can use the following command. Note that before removing a Docker Volume, you need to make sure that it is not mounted to any Container.

sudo docker volume rm $(sudo docker volume ls -q)

Removing all the Docker Volumes

To verify whether all the volumes have been deleted or not, you can use the Volume list command.

sudo docker volume ls

verify deletion

Last Updated : 05 Nov, 2020
Like Article
Save Article
Similar Reads