Search code examples
dockermounted-volumes

Orphaned Docker mounted host volumes?


I just inspected my /var/lib/docker/volumes folder and discovered that is bursting with folders named as Docker UUIDs each of which contain a config.json file with contents along the lines of

{"ID":"UUID","Path":"/path/to/mounted/volume","IsBindMount":true,"Writable":true}

where

/path/to/mounted/volume

is the path to the folder on the host that was mounted on to a docker container with the -v switch at some point. I have such folders dating back to the start of my experiments with Docker, i.e. about 3 weeks ago.

The containers in question were stopped and docker rm'ed a long time ago so I cannot see that those entries are not past their sell-by date. This begs the question - is the left over I am seeing a bug or does one need to manually discard such entries from /var/lib/docker/volumes?


Solution

  • For Docker 1.9 and up there's a native way:

    List all orphaned volumes with

    $ docker volume ls -qf dangling=true

    Eliminate all of them with

    $ docker volume rm $(docker volume ls -qf dangling=true)