How to cleanup Docker resources
Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...
WARNING: Use at your own risk, always test with the --dry-run parameter first. If it's not compatible with your system or Docker version it will delete all your volumes. Shellscript to delete orphaned docker volumes in /var/lib/docker/volumes and /var/lib/docker/vfs/dir
Delete volumes #
$ docker volume rm $(docker volume ls -qf dangling=true)
$ docker volume ls -qf dangling=true | xargs -r docker volume rm
Delete networks #
$ docker network ls
$ docker network ls | grep "bridge"
$ docker network rm $(docker network ls | grep "bridge" | awk '/ / { print $1 }')
Remove docker images #
$ docker images
$ docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
$ docker images | grep "none"
$ docker rmi $(docker images | grep "none" | awk '/ / { print $3 }')
Remove docker containers #
$ docker ps
$ docker ps -a
$ docker rm $(docker ps -qa --no-trunc --filter "status=exited")
Resize disk space for docker vm #
$ docker-machine create --driver virtualbox --virtualbox-disk-size "40000" default