How to clean docker devicemapper folder properly ?
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 volumesdocker volume ls -qf dangling=true | xargs -r docker volume rm# Remove untagged ("<none>") imagesdocker images --digests --format '{{.Repository}}:{{.Tag}}@{{.Digest}}' | sed -rne 's/([^>]):<none>@/\1@/p' | xargs -r docker rmi# Remove dangling imagesdocker images -qf dangling=true | xargs -r docker rmi# Remove temporary filesrm -f /var/lib/docker/tmp/*