How to remove Docker volumes step by step

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 efficiency and performance of your container platform.

When should you remove Docker volumes?

A Docker volume is an isolated storage area that can be used by Docker containers to store files, configurations, logs or other data throughout the container lifecycle. These volumes are independent of container instances and can be easily created, managed and removed. If you uninstall containers 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 environment that is clean and tidy. By getting rid of unused volumes, you reduce the complexity of your container infrastructure. In cloud-based environments, 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 accessible after it has been removed. In particular, this can help to prevent data breaches.

It’s important to be careful when removing Docker volumes to ensure that data needed by running containers as well as other important data isn’t deleted. This is why we recommend creating backups before deleting a Docker volume. When performing regular maintenance on your Docker infrastructure, you should look for obsolete volumes and remove them.

Further information 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
  • Flexibility 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 specifically delete volumes by specifying 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 information 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 containers. Removing them will irretrievably remove all the data they contain.

How to remove unused Docker volumes

Unused Docker volumes are volumes that are no longer associated with containers or services. Deleting these volumes can help you free up storage space that isn’t being used, allowing you to better manage your Docker infrastructure. 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 confirmation 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 associated with named volumes, the container will be removed, but all volumes associated with that container will remain intact. The volumes will still be available on your system. Other containers will be able to use them, and they will keep their user-defined name.

When it comes to unnamed volumes, these will be irreversibly 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 associated 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 associated 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 difference is between images and containers, you can find out in the article Docker images vs. containers.

Was this article helpful?
We use cookies on our website to provide you with the best possible user experience. By continuing to use our website or services, you agree to their use. More Information.
Page top