怎样删除docker中没有被使用的数据卷(volume)?
如果docker占用宿主机的磁盘空间很大,并且通过
docker system df
命令检查,发现
volume占用空间比较大,并且有一定的可回收空间,
这个时候,该如何来释放这些数据卷占用的空间呢?
方法非常的简单。
执行下面的命令,就会将那些未被使用的数据卷给清理掉
docker volume prune
执行过程如下:
输入确认的 y 之后,就会进行数据卷的清理【那些没有被任何容器使用的本地volume】
root@nctest-snap-test-02 ~]# docker volume prune WARNING! This will remove all local volumes not used by at least one container. Are you sure you want to continue? [y/N] y Deleted Volumes: e220820b8eb9dfb4326bc3fb19e86f3c64a911c0a571e11b5a3a255565832c59 f6ec74bd8f086eec852d69547a5e5b2366c7d394e3e4ed8367d7975b8321caaf 494ef2bdd9f90a83ba1e204dab333d5722748463a64025e9b381ed3779120658 01b6a3a4ae4f78b49948384617a1500f46a39222cdb69b997dbad33d0d4bb148 20d8b04dc2c9f8ac84e906f66a97282981deb2048da4fb372ca6211457cee23d 873762fd68671a7ff17c17d998d05e7a929a17fbb0a2ccce44c705981d2d68ef a75faca061538b72d5305adef50b77c031ac83af835c2f77b2ee63a5f9a4cb66 ab09095854535d66b3be9548d07684e76159db1c7d554ba2db7d8f228a4af9c7 a871b2d7e0af8fef22e152d8d8dbc664c3db4a041e1f0ef4fa1a009b11691ec4 3234fe654fa6b0fd3ab0350e9f6ac9450dfcd06f4f2397bed76e6081300f6fa3 2eaf39411106a30d4cfa5e0aae9275860b87a4d5a0ff7ceb6d51b2074ca944e7 445fb5500c5a71c51eafb4abb74870c2132138be59ecf34b8ac4a87f3751eda6 c6fa6574cea4dda7a84a11f2aae62791c57c74aa09d76aa408e63f6b6833357f ca1e3124a69e4ede52ce2139f2173105d9e580793a2ac40af6639814caeaa4f3 8de6f48d24780dd6f784b065f582514bff75df770b3ff0b45b64aa4559e57856 8de91ac691df2335ba3f55866a096101d781d51ade9445206ec8173cf67ea738 e2608f95c3dcb330196ccfb9e01cc2f3ffd594a28883b5a3d1e649de489c559d pinpoint-docker-master_data-volume d60a91fe2ce1e8abcb0481e27fdae49b18f830a5dc6b53fb78a2a8acc03c2002 517d20daee0ff407db15a7c0b03691945ac79e501ccc29c0e8cb332e98ea35d3 53fe182f98fa877f4e8a596d4213c72905c33e13f0bc48dc0f4f35a3a167402e 6ac3fa39c685396310ee9c1da218679ec23db70d36427e9ea618806a36399b72 6ba39a2d1a535dd94af405f8bfa1dbc3850bfb7916dfc8887953bf5f6e385f51 360c13a331d7ef13d9175f36c84cf4a9efe2e90004ddd6b28efadf9699f0f507 87e374d4c5e20b860f1d4c1c13ab2a7f92878bedc015fe3f3116ef11054b4b3c anchore_anchore-db-volume ce5f7777c4774b447f2eec0ecb7ffbf8f683f3f03bb4733a23649c775515f3c1 727c5b3df537e25d7d2881119d7c78e4a3322f1b8728ef3bea7c4901f1cce88f 792b29a02390aa5d47743307b880efcd409c6b07d5b82795a3e14c4d34d27439 897f57f20c4a2e0d50013ef96c82a8342484c9248b2c5ba69c3c379cda5a87dd b1ff6043a51f56a4055dc01b0e21b863ee2d8858f2dfca04e8a54dd047abf74c 2d9d7ff592b5e1b390fbafddd3a7e4f80ad5b519302070c91dad1e24dcbfee49 53b52d7ff16275106adeb0a4a6a6a3fb80a078f4b6e6ea7386253f02396b8d23 4f53b1742573d5e442047642bc4139b7dad637c384c41386835beda3f38e1064 my-vol 7b5769045cccfb59de9301432220a4da86946774e70681ec85c640c393beb842 ed66ff4c1088c4f917d51d0a4507d6915b5c9466872862969eea477cc1f4d095 18b50d674749802b297713cbafcb0266486c1be5ff5e914dbde13d06999085d8 958a3cf5e169a7c7b0af08ed0999fd8e9ba20a537b6ba447f5cb525e5cf62447 e1033960ae7c14aca5ee4cfce0ab34a14d2bc0f7eb33b6d7f65c71aa314e74cc 1909eecd7d5dc8114c8b34a11ef992075430281a52e34faf01557bdb6f15f191 34246b7cd55a1f7c9162b1fdbeb59d0f4c8e1550edd874f84ec4a0810eb862ec 49a53ee471bb0e2d480ed64e7b514c057101ad69d2a134fc462eab74533ac90e 5c4bd6d7fbdf4805e429c5b8a8d0b304dc1454157bdb9bc757f2c34d568719f3 fea84acdc909f2f66f841e48865a41ec41dabfa5039505d203ba40f5ffe71f2e 494650fcf1def9df852060e9f547bd971ad4ac3627587831be81b495afb69218 5f60d097b2e6e5bd544642ee3a23b55eddcc3a2e338f09dfff29ed1edce600f1 2bf4b39c3f1e7d13b80610ceb8c6bb5692393f9542e78d2ef1431de118cca7de 6868db7d9220591a2514706b890e19b9a20fe24313f4cbe8e31ef8aed6b2d6a5 331f024d252c799c3bac6779a39b6a6ace1b39b4656d68b1f1d4190c94b36a73 fe7735e16a0cc92e8bf112d79fd2d69e341d27fb4d928c6aa63078647d4ade15 c3fb20d4e585a95de96c5cc559506d2ecc7bf3336e6ee9af43316f49ad42637b e22391b97164fadf5971457768f1be953000016dbcac8f1de414550054aa43cf 748cda2a493f71049cebc91839f2118ada8f0cd3313b811674069e75b7c91063 c0d7d2995bcc23383c019efc6f653f028fd397f9578273a65cdc5707c3866390 3fab0aa992a89f5d7986a9ad559b005c9078c7d1991e242bef0ae6990ef27933 ebd4c50155c0db8cce88ff4254c7cfc3b4151f413804fd5afd60c6067acc7707 f457125bad2ab614b515c0281891948693e80617e5bdb02dafa75c9cb4092a76 8b9cf33d6e414bdf660b7080563b2212a8c154d80f7f8db5b0f09da08eb6201b e4d9ee8432e825dac6a43c19685f843cc379e9924ce83bcb2b560f1172256515 pinpoint-docker-master_mysql_data Total reclaimed space[总回收空间]: 5.225GB
最后会提示,本次操作一共释放的空间的大小。
当然了,如果不想输入 y,而是直接的确认,直接用下面的命令
docker volume prune -f
ok,到这里,我们就完成了对docker宿主机上未被使用的volume的清理工作。