Docker: list named volumes only

docker volume ls doesn’t appear to provide an easy way to only list named volumes. You can list all volumes easily enough, and you can list only anonymous volumes with something like docker volume ls -f label=com.docker.volume.anonymous. If it provided a way to negate the search term, you could get just the named volumes, which might be useful for various purposes (backup, moving volumes between servers, etc.).

A little bit of shell wizardry will get you what you want:

v=`docker volume ls -q`; for i in `docker volume ls -f label=com.docker.volume.anonymous -q`; do v="`echo $v | sed "s/$i//"`"; done

This lists all volumes, and then removes the anonymous volumes.

Leave a Reply

Only people in my network can comment.