Orphaned Docker mounted host volumes?

妖精的绣舞 提交于 2019-11-29 19:35:49

For Docker 1.9 and up there's a native way:

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:

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. To delete the volume from disk, you must explicitly call docker rm -v against the last container with a reference to the volume. 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.

For Docker 1.13+ and the ce/ee 17+ release numbers, use the volume prune command

docker volume prune

Unlike the dangling=true query, this will not remove "remote" driver based volumes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!