user12341234
user12341234

Reputation: 1487

docker container ls --size not accurate, how to get accurate container size?

one of my docker container seems to grow and docker is not tracking the size. It will go up in size 20gigs in a few days and docker container ls --size still shows 1gb in size including virtual. I know it's 20gb because if I remove the container I get 20 gb freed. Is there a way to get an accurate measurement?

Upvotes: 1

Views: 2527

Answers (1)

helt
helt

Reputation: 5197

In my case, the container log was growing over a few months, and now reaching a tipping point.

My solution is to truncate the logs file (:facepalm:) as described here: How to clear the logs properly for a Docker container?

Verify logs size

check docker container sizes:

root@example:/var/lib/docker/containers# docker ps --size -a
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                                      NAMES               SIZE
0117e099a9b0        ix                      "/docker-entrypoin..."   8 months ago        Up 2 minutes        px                                         cx                  2B (virtual 132MB)
...

check actual disk usage:

root@example:/var/lib/docker/containers# find . -type d -maxdepth 1 -exec du -hs {} 2>/dev/null \;
45G     .
37G     ./0117e099a9b04a36817c9a51f20f89571baeb3fe1b2a011695929d9bf381600f
...

Dive into the culprit (0117e099a9b0) to see that the log file which is not measured:

root@example:/var/lib/docker/containers/0117e099a9b04a36817c9a51f20f89571baeb3fe1b2a011695929d9bf381600f# ls -lssh
total 37G
 37G -rw-r----- 1 root root  37G May 27 08:44 0117e099a9b04a36817c9a51f20f89571baeb3fe1b2a011695929d9bf381600f-json.log
...

Upvotes: 3

Related Questions