docker clear

Combo:

1
2
3
4
5
6
# Most popular modern way to clean
docker system prune
# same but all images and volumes
docker system prune --volumes --all
# say "yes" automatically
echo 'y' | docker system prune

I encountered btrfs problems: docker says it has no volumes, but in fact
they exists. I want delete all btrfs volumes with word docker in path
limited by 400 pcs for run:

1
sudo btrfs subvolume delete --commit-each --verbose $(sudo btrfs subvolume list / | grep docker | awk '{ print "/"$9 }' | head -n 400)

Old fashion way:

1
2
3
4
5
6
7
8
9
10
# Delete all containers with volumes; Usefull for gitlab-ci
docker rm -v $(docker ps -a -q)
# Delete all exited containers with volumes
docker rm -v $(docker ps -a -q --filter status='exited')
# Delete all images
docker rmi $(docker images -q)
# Clear images without tags or names..
docker rmi $(docker images | grep '^<none>' | awk '{print $3}')
# Remove old volumes
docker volume rm $(docker volume ls -qf dangling=true)