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:
root@s5:~ # docker volume ls -q -f "dangling=true" 7b8baf0d804862c1a5daf8b5770b7d21ce7051d429815412e15b5ded95cb1d36 15a2e1552ab9ac37d7ab4f65d168894c3ea7d798000e90d8ab6426f5fecf42f3 81c68768733ae6fce19d256e20859aa6772875448126c7655c8d455c0067fdb3 83f9e08b9e23f4218189fe115b96c88eec59142f9ba9c39f7e7181298a7c9a70 92cf29ef5e3d42ab77d6467aae7a201f2aa04d92f369ffd6b09b84f217398565 307f5debc78882b6b46695c8f7a66298e0f90bdbf5b89833d6096775a1eed843 3013b332c97cff9e344ac48aa1d850075dba83ab68d177e340c4d357834812df 3910ca56fae2a73b546ebd9e8e665bea9770287f5a86a8c217b03e731843e9b7 5577dfc4792afad0bca22cd7d3193bfdf5148d0440e3a4bdec3d8cfeea5cccd0 374764091f95d2a998045b81ad0bc860cddf8474500e4069df275b400c6c43fe a754d3eda4c754952ffdbd62d311d1ae7db80ff94721a2df56a5092c53bb2e10 a4031051a268838724a1d7ca2cd5306c345074d2893556a7a16c1399c9682085 afa4d8b0cfd547f27246156cd6337f9a38d856ee54e998b501c6e99b62bb190b bf2c587c94688e358ebf622ce892a77f684242c0bf4d638e2e4937bab29b99b5 c5d5c25dcfc4e001fffc7a4d72e2f9506512f9b2720ad6d1d10c85c47aa1dab8 c83435df3fd742e8095c2933ea4032968db712726bbb8bcbdda433f1f019dd63 cb5732ba63df4dc76c3d1655b02f869517ad3edcc214515ef8f4ad6abd087eed d2d5479a0c376001951fe446c018e02808211d0cc2a0989a2beb52dd54aa19a1 d8aaf5d10c1034573558009eb6dcdfb65443cdb3f82f40ffa6a3c1d79419e7c8 dcf8989f67dda9a65792d9b2a29083d1e24363cd75cdc3c9ef5c179274416c64 e07e0049de9fac106a82be1cb61fe1734087d97f4c6c553d121991dacf376c5d e53ee798261fd220db2f023713cfe34ca7ed101165addd63352e3d6090c251f6 f7092dc19a8bb1b5a388d15f9b7ab4f4bf7aa6986ab57f4af3a2a703b737bfed
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:
root@s5:~ # docker volume rm $(docker volume ls -q -f "dangling=true") 7b8baf0d804862c1a5daf8b5770b7d21ce7051d429815412e15b5ded95cb1d36 15a2e1552ab9ac37d7ab4f65d168894c3ea7d798000e90d8ab6426f5fecf42f3 81c68768733ae6fce19d256e20859aa6772875448126c7655c8d455c0067fdb3 83f9e08b9e23f4218189fe115b96c88eec59142f9ba9c39f7e7181298a7c9a70 92cf29ef5e3d42ab77d6467aae7a201f2aa04d92f369ffd6b09b84f217398565 307f5debc78882b6b46695c8f7a66298e0f90bdbf5b89833d6096775a1eed843 3013b332c97cff9e344ac48aa1d850075dba83ab68d177e340c4d357834812df 3910ca56fae2a73b546ebd9e8e665bea9770287f5a86a8c217b03e731843e9b7 5577dfc4792afad0bca22cd7d3193bfdf5148d0440e3a4bdec3d8cfeea5cccd0 374764091f95d2a998045b81ad0bc860cddf8474500e4069df275b400c6c43fe a754d3eda4c754952ffdbd62d311d1ae7db80ff94721a2df56a5092c53bb2e10 a4031051a268838724a1d7ca2cd5306c345074d2893556a7a16c1399c9682085 afa4d8b0cfd547f27246156cd6337f9a38d856ee54e998b501c6e99b62bb190b bf2c587c94688e358ebf622ce892a77f684242c0bf4d638e2e4937bab29b99b5 c5d5c25dcfc4e001fffc7a4d72e2f9506512f9b2720ad6d1d10c85c47aa1dab8 c83435df3fd742e8095c2933ea4032968db712726bbb8bcbdda433f1f019dd63 cb5732ba63df4dc76c3d1655b02f869517ad3edcc214515ef8f4ad6abd087eed d2d5479a0c376001951fe446c018e02808211d0cc2a0989a2beb52dd54aa19a1 d8aaf5d10c1034573558009eb6dcdfb65443cdb3f82f40ffa6a3c1d79419e7c8 dcf8989f67dda9a65792d9b2a29083d1e24363cd75cdc3c9ef5c179274416c64 e07e0049de9fac106a82be1cb61fe1734087d97f4c6c553d121991dacf376c5d e53ee798261fd220db2f023713cfe34ca7ed101165addd63352e3d6090c251f6 f7092dc19a8bb1b5a388d15f9b7ab4f4bf7aa6986ab57f4af3a2a703b737bfed And justt to be sure, let's re-run the command that lists unused Docker volumes:
root@s5:~ # docker volume ls -q -f "dangling=true" root@s5:~ #
As you can see, there's nothing returned now – which means all the volumes were indeed removed.
See Also
- Offiicail Docker website
- Docker @ Unix Tutorial
- Migrate Docker container to another server
- Stop Docker Containers
- List Docker Containers
Leave a Reply