英文:
Docker creating hundreds of volumes that cannot be pruned
问题
我们有一台运行在Ubuntu服务器上的服务器,运行了几个Docker下的测试环境。今天系统空间不足,我最终发现/var/lib/docker
的空间已经增长到了826 GB,其中/var/lib/docker/volumes
单独占用了600 GB。
原来Docker已经创建了超过1,300个卷:
$ docker system df
类型 总数 活跃 大小 可回收
镜像 12 12 9.271GB 447.8MB (4%)
容器 12 10 405.9MB 62.84MB (15%)
本地卷 1307 8 634.8GB 630.8GB (99%)
构建缓存 3586 0 19.05GB 19.05GB
我尝试过docker volume prune
(还在此之前强制清理了镜像和容器),但只删除了一小部分的卷。
我们有另一台具有相同测试环境的Docker服务器,看起来完全不同(即正常),只有9个卷:
$ docker system df
类型 总数 活跃 大小 可回收
镜像 13 13 10.07GB 447.8MB (4%)
容器 14 10 312.2MB 111.7MB (35%)
本地卷 9 9 5.212GB 0B (0%)
构建缓存 0 0 0B 0B
如果我检查其中一个卷,以查找它属于哪个容器或镜像,我什么也得不到:
$ docker ps -a --filter volume=ff17641242297f3f9f3a63b2c328168f93c514e6e41cc3ed19bfbcb192acb5c7
容器ID 镜像 命令 创建时间 状态 端口 名称
然后我尝试了一个更激进的解决方案:
$ docker system prune -a -f
它删除了很多构建缓存对象(总共21 GB),但没有删除卷。
Docker是如何创建了1,300个无法清理的卷?我该如何修复这个问题?
请注意,我发现了为什么我的Docker卷空间不足? ,但那里的答案并不适用,所以我认为我的问题是不同的。
英文:
We have an Ubuntu server that runs a few test environments under Docker. The system ran out of space today, and I eventually found that /var/lib/docker
had grown to 826 GB with /var/lib/docker/volumes
alone making 600 GB thereof.
Turns out that docker has created over 1,300 volumes:
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 12 12 9.271GB 447.8MB (4%)
Containers 12 10 405.9MB 62.84MB (15%)
Local Volumes 1307 8 634.8GB 630.8GB (99%)
Build Cache 3586 0 19.05GB 19.05GB
I tried docker volume prune
(and also with force-pruning images and containers before that), but that removed only a handful volumes.
We have another server with the same test environments under Docker, and it's looks totally different (i.e. normal) with only 9 volumes:
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 13 13 10.07GB 447.8MB (4%)
Containers 14 10 312.2MB 111.7MB (35%)
Local Volumes 9 9 5.212GB 0B (0%)
Build Cache 0 0 0B 0B
If I check one of these volumes to find out which contain er or image it belongs to, I get nothing:
$ docker ps -a --filter volume=ff17641242297f3f9f3a63b2c328168f93c514e6e41cc3ed19bfbcb192acb5c7
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
The I tried a more radical solution:
$ docker system prune -a -f
It deleted a lot of build cache objects (21 GB in total), but no volumes.
How can it be that Docker has created 1,300 volumes that cannot be pruned? And what can I do to fix that?
Note that I found Why did my docker volume run out of disk space?, but the solutions given in the answers there do not work, so I assume my problem is a different one.
答案1
得分: 0
这个命令最终完成了它:
docker volume rm $(docker volume ls -q --filter dangling=true)
根据文档,docker volume prune -f
实际上应该完成这个任务,但实际上没有。根据这个答案,上面的命令是“旧的方式”来完成这个任务,但显然,这也是它实际上能正常工作的方式。
英文:
This command eventually did it:
docker volume rm $(docker volume ls -q --filter dangling=true)
According to the docs, docker volume prune -f
should actually do the job, but it didn't. According to this answer, the above is "the old way" to do it, but obviously, it is the way it actually works, too.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论