Remove Unused Volumes in Docker

docker-containers-unixtutorial

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

 




Backblaze 6.0 released

Screen Shot 2019-02-09 at 11.25.41.png

Backblaze just updated to version 6.0 earlier this week. If you didn’t know, Backblaze is possibly the best cloud backup solution that exists for Mac/Windows clients. It also supports a lot of open-source, free and commercial tools for Linux backup (Duplicity, qBackup, etc) via Backblaze B2 solution – plus there’s an API you can use for programmatically managing your backups strategy.

Backblaze Hard Drive Stats

Before I start talking about Backblaze Cloud Backup, I just want to mention another great thing Backblaze do – and it’s actually how I discovered them many years ago: Backblaze Hard Drive Stats (for 2018).

Because Backblaze are using so many hard disks in their datacentres, they are going through a number of makes and models, so every few months there’s an updated chart of how many disks fail. These are enterprise grade disks, so you’re unlikely to be buying the same models for your desktop PC, but I found these useful when building my very first home-grown mdadm based RAID arrays. I’ve moved on to Synology NAS since then but consult Backblaze hard drive stats regularly when shopping for new disks. Highly recommended!

Backblaze backup for MacOS

I’ve been a Backblaze user for 3 years now, with backed up amount growing steadily over the years. I have yet to require a full restore (fingers crossed!) but have used the Backblaze cloud via desktop and especially on iPhone for quickly accessing a file or two. Because Backblaze is a continuous backup solution, it’s a great option for accessing any of my laptops’ (backed up) files remotely from my iOS devices.

Backblaze for personal use and small businesses charges per backed up computer and not per amount of data you backup. You can’t backup network drives, but can backup any USB disks – so what I do is plugin a 3TB disk every few weeks, make important backups from my network storage to it, and then Backblaze picks it up and puts it into the cloud.

Backblaze 6.0 improvements

  • apparently, it’s 50% faster app now!
  • it’s now possible to prevent backups on certain WiFi networks (like mobile hotspot ones) using built-in Network Management
  • it’s possible to save certain files into B2 cloud (enterprise offering) – this will cost extra ($0.005 gigabyte/month I think – so still pretty cheap at $5 per TB) but should allow API access to your backups and many other really cool things

Why I like Backblaze Cloud Backup

Backblaze Pricing Model

Pricing is per computer system, not per amount of data. So your data needs will grow, but that won’t mean you’ll have to pay more.

I have 2TB of data stored in Backblaze and think it’s a great value for money:

Screen Shot 2019-02-09 at 11.35.34.png

Steady and Fast Performance

Never had any complaints at all, very solid application on MacOS with straightforward interface and easy to read stats. You can throttle network traffic so that backups don’t kill your home internet, so it’s a well implemented solution.

Backup State Inheritance

This I had used a few times – needed to move from one disk to another. So if I replace my external hard disk with a newer and/or larger model – instead of having to re-upload everything from scratch, I can just point Backblaze to the new disk and help it inherit the backup state from the previous disk. Granted, I have to make sure new disk has the same data the old disk had first! 🙂

Backup Restores by mail

Never used it, but someday probably will! For large or full restores, it’s faster to get your backup data on a disk or USB flash disk, rather than download it all from the cloud. For a reasonable enough fee, Backblaze can send you a hard disk with your data so that you an restore faster it and then send the disk back.

That’s it for today! Just wanted to share and to recommend Backblaze. If you decide to check it out, please use my affiliate link: https://secure.backblaze.com/r/01gyum

See Also