The official Docker documentation mentions that I need to run docker rm -v containername
to specifically remove a data volume. But what do you do if you already removed all the containers referencing the specific data volume ?
Docker – Removing Docker data volumes
docker
Related Topic
- Ubuntu – How to auto-start docker containers at system boot
- Docker data volumes with couchbase
- Docker – Container Time & Timezone Issues
- Linux – Docker cannot access volumes
- Docker – Why does docker-machine clear data on restart
- Docker – How is Docker Compose version 2 “volumes” syntax supposed to look
- Docker – How to use OverlayFS with Docker volumes
- Docker – How to persist all Jenkins data on an EBS volume in docker
Best Answer
Before version 1.9, Docker didn't provide any way to remove dangling volumes.
If such volumes are taking too much disk space and you want to take matters into your own hands though, you can manually delete the volumes by first identifying the ones which are in use. You can run
docker inspect -f '{{ .Volumes }}' containername
to find the location in the file system of the volumes in use, and then delete everything except those. If you have lots of containers, you can runfor x in $(docker ps -qa | sed '1d'); do docker inspect -f '{{ .Volumes }}' ${x}; done
to loop through the containers and list the volumes.Better yet, you can use the Python script here, the prerequisite is to install the python API client for Docker
pip install docker-py