docker - 如何删除(已删除)docker-container的docker-volume?

标签 docker docker-volume

我有运行大量Docker容器的测试。每个都有一个音量。
如何知道需要删除的卷名?
例如:

~ docker run -d registry:2 
~ docker volume inspect c80fc65a79039d70cf54b3af3ab66b378dec42d0757928ae94277b197d8d8104
[
    {
        "CreatedAt": "2020-08-14T11:33:50Z",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/c80fc65a79039d70cf54b3af3ab66b378dec42d0757928ae94277b197d8d8104/_data",
        "Name": "c80fc65a79039d70cf54b3af3ab66b378dec42d0757928ae94277b197d8d8104",
        "Options": null,
        "Scope": "local"
    }
]
手动停止并删除registry:2容器后,该卷仍然存在。
我不想删除所有卷,因为其中一些仍在使用中。

最佳答案

您无需自己确定卷名。实际上,您在这里有多个选项。
如果要清理,可以在--rm上使用docker run标志
引用:docs.docker.com: Clean Up (--rm)

If you set the --rm flag, Docker also removes the anonymous volumes associated with the container when the container is removed. This is similar to running docker rm -v my-container. Only volumes that are specified without a name are removed. For example, when running:


使用docker system prune --volumes命令清理至少一个容器未使用的所有卷
引用:docs.docker.com: docker system prune

Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.


获取助理卷
如果您真的想获取容器的体积,可以使用代码段
docker inspect -f '{{ .Name }}{{ printf "\n" }}{{ range .Mounts }}{{ printf "\n\t" }}{{ .Type }} {{ if eq .Type "bind" }}{{ .Source }}{{ end }}{{ .Name }} => {{ .Destination }}{{ end }}{{ printf "\n" }}' <continaer-id>

关于docker - 如何删除(已删除)docker-container的docker-volume?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63412096/

相关文章:

docker - Windows 上的 Boot2docker 代理

docker - 使用 TCPIP 的多节点 docker 环境中的 Hazelcast

docker - 如何将文件卷挂载到远程 docker 守护进程?

mysql - 从另一个容器中启动容器时,docker-entrypoint-initdb.d为空

docker - 在 Docker Swarm 内使用 “bind” 卷挂载和 docker-compose 文件

docker - 权限被拒绝安装现有卷(没有sudo)

amazon-web-services - 为什么我在 docker/aws eb 上收到权限被拒绝错误?

java - 更新镜像后让 Jenkins "update"运行 docker 容器的最佳方法

ruby - $ GEM_HOME和$ GEM_PATH在旅客中设置错误

docker - 如何创建docker卷设备/主机路径