Docker Community Forums

Share and learn in the Docker community.

How to clean unsed Docker stuff under /var/lib/docker


(Ghassen Khalil Ati) #1

It’s been a while since I start using Docker on my VPS for some apps like GitLab and SonarQube and other apps that I am creating for personal purposes.
Lately I noticed that there is no space left on my disk and by using ncdu command I found that /var/lib/docker is taking more than 60GiB :

22,5 GiB [######### ] /overlay2
15,1 GiB [###### ] /containers
122,3 MiB [ ] /swarm
44,8 MiB [ ] /image
524,0 KiB [ ] /containerd
128,0 KiB [ ] /network
20,0 KiB [ ] /plugins
20,0 KiB [ ] /builder
4,0 KiB [ ] /trust
4,0 KiB [ ] /tmp
4,0 KiB [ ] /runtimes

I hesitated about deleting some folders under /volumes and /containers having names like for example ‘ff5aaf8f8d5cd262a5004f5bf3afa4c270aab417f5b7f78594330538c178cfc5’ because I don’t know if it’s going to impact some apps or not !
So is there a proper way to do the cleaning of this mess and getting rid of unuseful stuff ?

Thank you in advance

(Archimedes Trajano) #2

docker system prune -f --all and just add it to the crontab.

HOWEVER… make sure you don’t do builds when that is executed. Otherwise you may lose some images.

(Martin Terp) #3

If you use @trajano’s approach, make sure you dont have containers that can die, because if they stop for some reason, and you run that command, they will be deleted with attached storage and image

(Ghassen Khalil Ati) #4

I found some solutions that worked fine for me :

#delete the content of /var/lib/docker/volumes
docker volume rm $(docker volume ls -qf dangling=true)

#delete old docker processes
docker rm docker ps -a | grep Exited | awk '{print $1 }' ignore_errors: true

#delete old images. will complain about still-in-use images
docker rmi docker images -aq

(Martin Terp) #5

Its basicly the same thing that prune does :slight_smile:

(Ghassen Khalil Ati) #6

Yes I finally found that’s the same thing … thank you anyway :slight_smile: