How to clean docker devicemapper folder properly ?

孤者浪人 提交于 2019-12-06 02:20:30

问题


I have some problem about the storage. The folder /var/lib/docker/devicemapper/ is taking 50% of my storage.

In the folder /var/lib/docker/devicemapper/mnt, I have many empty folders.

How can I properly clean docker devicemapper and remove all unused mapping ?


回答1:


With recent versions of Docker you can see the space used with:

docker system df

and prune it with:

docker system prune

The above command combines the prune command that exists for volumes, containers, images and networks:

docker volume prune

docker container prune

docker image prune

docker network prune

Each command has a --help option documenting a -f (--force) option to avoid asking you questions. It must be used with care.

-o-

On older versions of Docker I ran the script:

#!/bin/bash

# Remove dead containers (and their volumes)
docker ps -f status=dead --format '{{ .ID }}' | xargs -r docker rm -v
# Remove dangling volumes
docker volume ls -qf dangling=true | xargs -r docker volume rm
# Remove untagged ("<none>") images
docker images --digests --format '{{.Repository}}:{{.Tag}}@{{.Digest}}' | sed -rne 's/([^>]):<none>@/\1@/p' | xargs -r docker rmi
# Remove dangling images
docker images -qf dangling=true | xargs -r docker rmi
# Remove temporary files
rm -f /var/lib/docker/tmp/*


来源:https://stackoverflow.com/questions/44244176/how-to-clean-docker-devicemapper-folder-properly

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