DEV Community

Cover image for Docker high disk space usage ๐Ÿ’พ ๐Ÿ“ˆ
Andrea Pavone
Andrea Pavone

Posted on • Updated on

Docker high disk space usage ๐Ÿ’พ ๐Ÿ“ˆ

Did you find an heavy disk space usage on your server and you don't know what is the root cause?

If you do some tests with Docker or you're running some containers on your machine, the cause of this abnormal disk space usage might be just Docker ๐Ÿ‹!

For example on my Raspberry Pi 4 I've seen an heavy space usage on /var/lib/docker/ directory, specially on overlay2:

root@rpi4:/home/user# du -h -d 1 /var/lib/docker/
2,6M    /var/lib/docker/image
15G     /var/lib/docker/overlay2
5,2M    /var/lib/docker/containers
17G     /var/lib/docker/
Enter fullscreen mode Exit fullscreen mode

To fix this issue you can employ this command docker system prune see an example:

root@rpi4:/home/user# docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y
Deleted Containers:

Total reclaimed space: 14.04GB
Enter fullscreen mode Exit fullscreen mode

Do you want more information or simply read this article in original language (Italian ๐Ÿ‡ฎ๐Ÿ‡น)?

Top comments (4)

gholami1313 profile image
Mohammad Gholami

Most of the time we need many of those deleted images, so we have to pull them again and build the Dockerfiles.
You can also delete dangling images and it also saves lots of space for you:

docker rmi $(docker images -f "dangling=true" -q)
Enter fullscreen mode Exit fullscreen mode

or if you need root permission:

sudo docker rmi $(sudo docker images -f "dangling=true" -q)
Enter fullscreen mode Exit fullscreen mode
lebinhan profile image

I have (most likely) the same problem a month ago. At first I blamed docker for not optimizing its garbage collection. But the real problems was because of me, after trying to search for solutions on the internet and found nothing, I started to investigate my configuration. Turn out, I choose at least 3 realtime bug logger for my project, every second, each of them logged like ~100-200 lines of project status and they 'ate' almost 200gb of storage every day. In the past when I still working with real host machine, I had a script that clean all of the logs for me so I forgot that they log that much. So for anyone who faces the same problems, consider to check your logger as they might be a pain in your neck latter on.

cereal84 profile image
Alessandro Pischedda

It is a well known problem. Instead ti ordine everything I can suggest you to check if you have manu images born by docker build, in that casa use only docker image prune in order to avoid deleting volumes or networks (if you need them).

andp97 profile image
Andrea Pavone

I'm not the only one with this problem!๐Ÿคฆ๐Ÿปโ€โ™‚๏ธ๐Ÿ˜…