Docker taking much more space than sum of containers, images and volumes
Asked Answered
L

4

14

Docker running on Ubuntu is taking 18G of disk space (on a partition of 20G), causing server crashes. Commands below show that there is a serious mismatch between "official" image, container and volume sizes and the docker folder size.

What causes this and how can I cleanup ?

I already tried docker system prunewhich doesn't help.

du -sh /var/lib/docker

enter image description here

docker system df

docker

du -sh /var/lib/docker/*

enter image description here

du -sh /var/lib/docker/containers/*

enter image description here

Landin answered 17/12, 2019 at 11:18 Comment(2)
Does this answer your question? Why is docker image eating up my disk space that is not used by dockerIveyivie
Is your du command is printing out those PNG files directly? That's very unusual...I'd expect them to print out plain text. Can you replace the images with the actual text output of those commands? Is there application source code that's relevant to this question, or is it just about disk utilization on a Linux host?Photojournalism
S
5

You have two containers that are eating your storage. Those containers must be running, because you said you already ran docker system prune. Otherwise /var/lib/docker/containers would be empty.

So check why are those two consuming so much. Probably they are logging too much to stdout.

Shilling answered 17/12, 2019 at 12:4 Comment(3)
indeed, there is quite some logging. "virtual container size" is below 1G though, so I guess the log space of stdout is not included. Is there a way to delete logs in stdout without changing container ?Landin
you can try to truncate the log. If you keep running du, you'll see that probably the large file is one named <CONTAINER_ID>-json.log. So just truncating it should do the trick, in fact, I think that once I had to do so, but don't remember exactly, so proceed at your own risk :)Shilling
I followed this post to truncate logs (after stopping container) and everything looks fine: #42510502Landin
C
15

I was having the same problem. I solved my problem by deleting log files

sudo sh -c "truncate -s 0 /var/lib/docker/containers/*/*-json.log"

Link: How to clear the logs properly for a Docker container?

Cudbear answered 13/7, 2020 at 8:10 Comment(1)
Lifesaver. Surprisingly hard answer to come by.Tangier
S
5

You have two containers that are eating your storage. Those containers must be running, because you said you already ran docker system prune. Otherwise /var/lib/docker/containers would be empty.

So check why are those two consuming so much. Probably they are logging too much to stdout.

Shilling answered 17/12, 2019 at 12:4 Comment(3)
indeed, there is quite some logging. "virtual container size" is below 1G though, so I guess the log space of stdout is not included. Is there a way to delete logs in stdout without changing container ?Landin
you can try to truncate the log. If you keep running du, you'll see that probably the large file is one named <CONTAINER_ID>-json.log. So just truncating it should do the trick, in fact, I think that once I had to do so, but don't remember exactly, so proceed at your own risk :)Shilling
I followed this post to truncate logs (after stopping container) and everything looks fine: #42510502Landin
C
1

docker system prune should clean up old unused layers, I have managed to get lots of disk space back several times with this. Hope it helps.

Catnip answered 17/12, 2019 at 11:33 Comment(0)
M
0

Have you ever try this:

docker system prune --all --volumes
Misteach answered 18/8 at 4:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.