DEV Community

loading...
Cover image for Docker high disk space usage ๐Ÿ’พ ๐Ÿ“ˆ

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

andp97 profile image Andrea Pavone ใƒปUpdated on ใƒป1 min read

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:
64086f34849c92aa2aed8a8757d7c395fbd4a2d77103174bd23a9efc8e0ec333
7be7eda3b32971f39cf08629eaf6d8f42c2677d02f220e0a09a4d955fb0ff5bb
aef03c9d804ae46ed17fa3ecd602a6d335f810a025204f208b3d78186ef26864

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 ๐Ÿ‡ฎ๐Ÿ‡น)?

Discussion (4)

pic
Editor guide
Collapse
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
Collapse
lebinhan profile image
LeBinhAn_dev

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.

Collapse
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).

Collapse
andp97 profile image
Andrea Pavone Author

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