Keeping unused volumes around can lead to valuable resources such as storage space and computing power being wasted. By removing unused Docker volumes, you increase the ef­fi­cien­cy and per­for­mance of your container platform.

When should you remove Docker volumes?

A Docker volume is an isolated storage area that can be used by Docker con­tain­ers to store files, con­fig­u­ra­tions, logs or other data through­out the container lifecycle. These volumes are in­de­pen­dent of container instances and can be easily created, managed and removed. If you uninstall con­tain­ers that are linked to a specific volume and you no longer need the data contained in the volume, it makes sense to delete the volume as well.

It’s easier to manage and maintain a Docker en­vi­ron­ment that is clean and tidy. By getting rid of unused volumes, you reduce the com­plex­i­ty of your container in­fra­struc­ture. In cloud-based en­vi­ron­ments, unused volumes can end up leading to extra costs. Removing these volumes can help to reduce your monthly expenses. It also increases the security of your system, as sensitive data stored in volumes is no longer ac­ces­si­ble after it has been removed. In par­tic­u­lar, this can help to prevent data breaches.

It’s important to be careful when removing Docker volumes to ensure that data needed by running con­tain­ers as well as other important data isn’t deleted. This is why we recommend creating backups before deleting a Docker volume. When per­form­ing regular main­te­nance on your Docker in­fra­struc­ture, you should look for obsolete volumes and remove them.

Further in­for­ma­tion on Docker container volumes can be found in our Digital Guide.

Compute Engine
The ideal IaaS for your workload
  • Cost-effective vCPUs and powerful dedicated cores
  • Flex­i­bil­i­ty with no minimum contract
  • 24/7 expert support included

How to remove one or more specific Docker volumes

In Docker 1.9 and higher, you can remove specific volumes using the docker volume rm command. This command allows you to specif­i­cal­ly delete volumes by spec­i­fy­ing their names or IDs.

Step 1: List Docker volumes

To list Docker volumes, you can execute the command docker volume ls in the console. The output will be a table with in­for­ma­tion about the volumes you have, including names and IDs.

docker volume ls
bash

Step 2: Remove Docker volumes

Now you can remove volumes by entering their names or IDs separated by spaces after the command docker volume rm.

docker volume rm VOLUME_NAME_OR_ID VOLUME_NAME_OR_ID
bash

It’s best to make sure that the volumes you want to delete aren’t being used by running con­tain­ers. Removing them will ir­re­triev­ably remove all the data they contain.

How to remove unused Docker volumes

Unused Docker volumes are volumes that are no longer as­so­ci­at­ed with con­tain­ers or services. Deleting these volumes can help you free up storage space that isn’t being used, allowing you to better manage your Docker in­fra­struc­ture. To find out how to remove unused Docker volumes, read the steps below:

Step 1: List unused Docker volumes

If you execute the following command, you’ll receive a list of all the unused Docker volumes labeled as dangling on your system. These volumes can then be cleaned up or removed as necessary.

docker volume ls -f dangling=true
bash

Step 2: Remove unused volumes

The command docker volume prune asks for con­fir­ma­tion before it deletes the unused volumes. You can confirm this by either entering y or yes. Only do this if you are sure that you want to remove the volumes.

docker volume prune
bash

How to remove a Docker container and its volume

With the command docker rm -v container_name, you can remove a Docker container and at the same time delete all volumes connected to the container.

If you apply the command to a container as­so­ci­at­ed with named volumes, the container will be removed, but all volumes as­so­ci­at­ed with that container will remain intact. The volumes will still be available on your system. Other con­tain­ers will be able to use them, and they will keep their user-defined name.

When it comes to unnamed volumes, these will be ir­re­versibly removed along with the data they contain.

We explain how to remove a Docker container in more detail in another article in our Digital Guide.

How to remove a Docker volume as­so­ci­at­ed with a container

The -v flag stands for volumes and is the option you add to the docker rm command to specify that all volumes as­so­ci­at­ed with the container should also be removed.

docker rm -v container_name
bash
Tip

In another article, we cover how to delete a Docker image. If you’ve ever wondered what the dif­fer­ence is between images and con­tain­ers, you can find out in the article Docker images vs. con­tain­ers.

Go to Main Menu