You can list unused volumes using the filtering option of docker volume ls command. Once these are identified, it’s easy enough to remove such volumes altogether.
List dangling volumes in Docker
Relying on the dangling flag of a volume object, we can list all the dangling volumes as shown below:
Excellent! Now let’s remove these volumes.
Remove unused (dangling) volumes in Docker
We’ll use the docker volume ls output as the list of command line options for the docker volume rm command.
As always, we’ll get confirmation about each volume that’s just been removed:
And just to be sure, let’s re-run the command that lists unused Docker volumes:
As you can see, there’s nothing returned now – which means all the volumes were indeed removed.