[英]How to remove all docker volumes?
If I do a docker volume ls
, my list of volumes is like this:如果我做一个
docker volume ls
,我的卷列表是这样的:
DRIVER VOLUME NAME
local 305eda2bfd9618266093921031e6e341cf3811f2ad2b75dd7af5376d037a566a
local 226197f60c92df08a7a5643f5e94b37947c56bdd4b532d4ee10d4cf21b27b319
...
...
local 209efa69f1679224ab6b2e7dc0d9ec204e3628a1635fa3410c44a4af3056c301
and I want to remove all of my volumes at once.我想一次删除我的所有卷。 How can I do it?
我该怎么做?
The official command to remove all unused data (including volumes without containers) will be with docker 1.13删除所有未使用数据(包括没有容器的卷)的官方命令将使用 docker 1.13
docker system prune
If you want to limit to volumes alone, removing only unused volumes :如果您想单独限制卷,请仅删除未使用的卷:
docker volume prune
You also have docker image prune
, docker container prune
, etc:您还有
docker image prune
、 docker container prune
等:
See more at " Prune unused Docker objects ".在“修剪未使用的 Docker 对象”中查看更多信息。
See commit 86de7c0 and PR 26108 .请参阅提交 86de7c0和PR 26108 。
You can see it in action in play-with-docker.com :你可以在play-with-docker.com 中看到它的实际效果:
/ # docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1296a5e47ef3 hello-world "/hello" 7 seconds ago Exited (0) 6 seconds ago prickly_poincare
/ # docker system prune
WARNING! This will remove:
- all stopped containers
- all volumes not used by at least one container
- all networks not used by at least one container
- all dangling images
Are you sure you want to continue? [y/N] y
Deleted Containers:
1296a5e47ef3ab021458c92ad711ad03c7f19dc52f0e353f56f062201aa03a35
The current (pre-docker 1.13) way of managing volume was introduced with PR 14242 and the docker volume
command , which documents in its comment from July 2015:当前( docker 1.13 之前)管理卷的方式是通过PR 14242 和 docker
docker volume
命令引入的,该命令在2015 年 7 月的评论中记录:
docker volume rm $(docker volume ls -q --filter dangling=true)
Edited on 2017: This answer was given on Apr 16 '16 and now is outdated, and correct only for docker version prior to 1.13 please use the answer from @VonC, now it is marked as correct 2017 年编辑:此答案于 2016 年 4 月 16 日给出,现在已过时,仅适用于 1.13 之前的 docker 版本,请使用@VonC 的答案,现在它被标记为正确
To delete unused volumes you can use the built-in docker volume rm
command.要删除未使用的卷,您可以使用内置的 docker
volume rm
命令。 The rm
command also deletes any directory in /var/lib/docker/volumes
that is not a volume, so make sure you didn't put anything in there you want to save: rm
命令还会删除/var/lib/docker/volumes
中不是/var/lib/docker/volumes
任何目录,因此请确保您没有在其中放置任何要保存的内容:
Command to List volumes, little bit right than yours:列出卷的命令,比你的稍微好一点:
$ docker volume ls -qf dangling=true
Cleanup:清理:
$ docker volume rm $(docker volume ls -qf dangling=true)
more details about lshere , about rmhere关于 ls 的更多细节在这里,关于 rm在这里
This is what I've found to be useful: https://github.com/chadoe/docker-cleanup-volumes这是我发现有用的内容: https : //github.com/chadoe/docker-cleanup-volumes
Shellscript to delete orphaned docker volumes in /var/lib/docker/volumes and /var/lib/docker/vfs/dir Docker version 1.4.1 up to 1.11.x
用于删除 /var/lib/docker/volumes 和 /var/lib/docker/vfs/dir Docker 版本 1.4.1 至 1.11.x 中孤立的 docker 卷的 Shellscript
It basically does a cleanup of any orphaned/dangling volumes, but it includes a --dry-run
but it makes note of some docker included commands as well (which are referenced in prev comment)它基本上清理了任何孤立/悬空卷,但它包含一个
--dry-run
但它也记录了一些--dry-run
包含的命令(在上一条评论中引用)
Note about Docker 1.9 and up
关于 Docker 1.9 及更高版本的注意事项
To delete orphaned volumes in Docker 1.9 and up you can also use the built-in docker volume commands instead of this docker-cleanup-volumes script.
要删除 Docker 1.9 及更高版本中的孤立卷,您还可以使用内置的 docker volume 命令而不是此 docker-cleanup-volumes 脚本。 The built-in command also deletes any directory in /var/lib/docker/volumes that is not a volume so make sure you didn't put anything in there you want to save:
内置命令还会删除 /var/lib/docker/volumes 中不是卷的任何目录,因此请确保您没有在其中放置任何要保存的内容:
List:
清单:
$ docker volume ls -qf dangling=true
Cleanup:
清理:
$ docker volume rm $(docker volume ls -qf dangling=true)
Or, handling a no-op better but Linux specific:
或者,更好地处理无操作但特定于 Linux:
$ docker volume ls -qf dangling=true | xargs -r docker volume rm
要回答这个问题并从 Marc 那里借用,这有效:
$ docker volume rm $(docker volume ls -qf dangling=true | xargs)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.