简体   繁体   English

孤岛Docker挂载主机卷?

[英]Orphaned Docker mounted host volumes?

I just inspected my /var/lib/docker/volumes folder and discovered that is bursting with folders named as Docker UUIDs each of which contain a config.json file with contents along the lines of 我只是检查了我的/ var / lib / docker / volumes文件夹,发现它正在破坏名为Docker UUID的文件夹,每个文件夹都包含一个config.json文件,其中的内容沿着

{"ID":"UUID","Path":"/path/to/mounted/volume","IsBindMount":true,"Writable":true}

where 哪里

/path/to/mounted/volume

is the path to the folder on the host that was mounted on to a docker container with the -v switch at some point. 是主机上的文件夹的路径,该文件夹在某个时刻使用-v开关安装到docker容器上。 I have such folders dating back to the start of my experiments with Docker, ie about 3 weeks ago. 我有这样的文件夹可以追溯到我使用Docker进行实验的开始,即大约3周前。

The containers in question were stopped and docker rm'ed a long time ago so I cannot see that those entries are not past their sell-by date. 有问题的容器很久以前就被停了下来,并且很久以前就停泊了这些容器,所以我看不出那些条目没有超过他们的销售日期。 This begs the question - is the left over I am seeing a bug or does one need to manually discard such entries from /var/lib/docker/volumes? 这引出了一个问题 - 剩下的就是我看到了一个错误,还是需要从/ var / lib / docker / volumes手动丢弃这些条目?

For Docker 1.9 and up there's a native way: 对于Docker 1.9及更高版本,有一种原生方式:

List all orphaned volumes with 列出所有孤立的卷

$ docker volume ls -qf dangling=true

Eliminate all of them with 消除所有这些

$ docker volume rm $(docker volume ls -qf dangling=true)

From the Docker user guide: 从Docker用户指南:

If you remove containers that mount volumes, including the initial dbdata container, or the subsequent containers db1 and db2, the volumes will not be deleted. 如果删除装入卷的容器(包括初始dbdata容器)或后续容器db1和db2,则不会删除卷。 To delete the volume from disk, you must explicitly call docker rm -v against the last container with a reference to the volume. 要从磁盘中删除卷,必须使用对卷的引用对最后一个容器显式调用docker rm -v。 This allows you to upgrade, or effectively migrate data volumes between containers. 这允许您在容器之间升级或有效迁移数据卷。 - source - 来源

This is intentional behavior to avoid accidental data loss. 这是故意的行为,以避免意外的数据丢失。 You can use a tool like docker-cleanup-volumes to clean out unused volumes. 您可以使用docker-cleanup-volumes等工具清除未使用的卷。

For Docker 1.13+ and the ce/ee 17+ release numbers, use the volume prune command 对于Docker 1.13+和ce / ee 17+版本号,请使用volume prune命令

docker volume prune

Unlike the dangling=true query, this will not remove "remote" driver based volumes. dangling=true查询不同,这不会删除基于“远程”驱动程序的卷。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM