user11989037
user11989037

Reputation: 65

How do I clean docker?

An error occurred because there is not enough disk space I decided to check how much is free and came across this miracle enter image description here

Cleaned up via docker system prune -a and

docker container prune -f 
docker image prune -f
docker system prune -f

But only 9GB was cleared

Upvotes: 0

Views: 5191

Answers (6)

David Chou
David Chou

Reputation: 11

After Docker version 23, filter all=true may be help.

docker volume prune --filter all=true

Upvotes: 1

Muhammad Hasan
Muhammad Hasan

Reputation: 168

If you want, you could dig deep at granular level and pinpoint the file(s) which are the cause of this much disk usage.

du -sh /var/lib/docker/overley2/<container hash>/merged/* | sort -h

this would help you coming to a conclusion much easily.

Upvotes: 0

BMitch
BMitch

Reputation: 265210

From the screenshot I think there's some confusion on what's taking up how much space. Overlay filesystems are assembled from directories on the parent filesystem. In this case, that parent filesystem is within /var/lib/docker which is part of / in your example. So the df output for each overlay filesystem is showing how much disk space is used/available within /dev/vda2. Each container isn't using 84G, that's just how much is used in your entire / filesystem.

To see how much space is being used by docker containers, images, volumes, etc, you can use docker system df. If you have running containers (likely from the above screenshot), docker will not clean those up, you need to stop them before they are eligible for pruning. Once containers have been deleted, you can then prune images and volumes. Note that deleting volumes deletes any data you were storing in that volume, so be sure it's not data you wanted to save.

It's not uncommon for docker to use a lot of disk space from downloading lots of images (docker makes it easy to try new things) and those are the easiest to prune when the containers are stopped. However what's harder to see are the logs that containers are outputting which will slowly fill the drive within the containers directory. For more details on how to clean the logs automatically, see this answer.

Upvotes: 1

wearego
wearego

Reputation: 178

It could be your logging of the running containers. I've seen Docker logging writing disks full with logging. By default Docker containers can write unlimited logs.

I always add logging configuration to my docker-compose restrict total size. Docker Logging Configuration.

Upvotes: 0

Sahil Yadav
Sahil Yadav

Reputation: 108

Prune removes containers/images that have not been used for a while/stopped. I would suggest you do a docker ps -a and then remove/stop all the containers that you don't want with docker stop <container-id>, and then move on to remove docker images by docker images ps and then remove them docker rmi <image-name>

Once you have stooped/removed all the unwanted containers run docker system prune --volumes to remove all the volumes/cache and dangling images.

Upvotes: 1

Charles Desbiens
Charles Desbiens

Reputation: 1079

Don't forget to prune the volumes! Those almost always take up way more space than images and containers. docker volume prune. Be careful if you have anything of value stored in them though.

Upvotes: 0

Related Questions