Delete docker overlay2 and free up space on your Linux server
Warning: strong language ahead, needed to vent.
So this is going to be a short one, basically I was having issues with a server filling up with docker/overlay2 garbage and it was frustrating me way too much.
Running df -h showed:
Filesystem Size Used Avail Use% Mounted on
udev 982M 0 982M 0% /dev
tmpfs 199M 824K 199M 1% /run
/dev/vda1 18G 18G 457M 98% /
tmpfs 995M 16K 995M 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 995M 0 995M 0% /sys/fs/cgroup
/dev/vda15 105M 3.6M 101M 4% /boot/efi
tmpfs 199M 0 199M 0% /run/user/0
overlay 18G 18G 457M 98% /var/lib/docker/overlay2/8c1fcc6b0091c980e0bcf6d85f77ef94aa03ce59d2d5eba1
Yeah it's a smol machine and I was mainly running docker for batch jobs so I didn't wanna persist anything which left me wondering as to why in hell the stuff was just adding up and adding up... Especially that docker/overlay2 stuff seemed like a persistent mother in law, just getting bigger and bigger!
Following some internet wisdom I found out a lot people saying just run "docker system prune -af". Which actually does jack shit. I found a solution for non pruned af people like me.
So in case you have the same issue and don't store ANY DATA in docker containers or docker volumes do this:
systemctl stop docker
rm -rf /var/lib/docker/
systemctl start docker
and nuke that shit to oblivion! Enjoy the free space. I am too frustrated right now to explain why this works but whatever, closing the issue lmao.
Filesystem Size Used Avail Use% Mounted on
udev 982M 0 982M 0% /dev
tmpfs 199M 748K 199M 1% /run
/dev/vda1 18G 7.5G 11G 42% /
tmpfs 995M 16K 995M 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 995M 0 995M 0% /sys/fs/cgroup
/dev/vda15 105M 3.6M 101M 4% /boot/efi
tmpfs 199M 0 199M 0% /run/user/0
There is also a great way to reduce the log size for docker containers but that's easy to figure out and should be done during the initial installation of docker.
What BOGGLES the mind is that these are not sane defaults in a standard docker installation. Now throw Kubernetes in the mix and you'll be employed for the next 50 years...