Signup/Sign In

How to remove Volumes in Docker?

Volumes are used to persist data generated and used by Docker containers. We can create volumes separately using the docker volume create command and then attach it with a docker container.

Because volumes are created separately and then later attached to docker containers, when a container is removed, a volume is not removed along with the container, the volume stays. So you have to remove the volume separately.

List down Docker volumes

To list down all the docker volumes, you can use the docker volume ls command, like this:

docker volume ls

This will give you the names of all the docker volumes in your system.

docker volume ls

Then you can use the name of the volume to remove the docker volume.

Remove Docker volume

Once you have the name of the docker volumes that you want to remove then you can use the docker volume rm command to remove the docker volume.

docker volume rm volume_name

You can also remove multiple volumes together by mentioning the name of all the volumes together separated by space. For example,

docker volume rm volume_name1 volume_name2 volume_name3

Docker dangling volumes

You can use the docker volume ls command to list all the available docker volumes, including the dangling volumes.

Dangling volumes are the volumes that are not attached to any docker container. So if you wish to list all the dangling volumes, then you can use the following command,

docker volume ls -f dangling=true

Once you have all the dangling volumes listed, you can use the docker volume prune command to remove all the dangling docker volumes.

docker volume prune

If you want to remove a docker volume, then these commands will help you.

About the author:
I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight