dockerdu

Diffrence between real and showed by docker system df disc usage


I have docker in version 18.03.1-ce that support command docker system df. His output:

Images space usage:

REPOSITORY                               TAG                 IMAGE ID            CREATED ago             SIZE                SHARED SIZE         UNIQUE SiZE         CONTAINERS
registry.gitlab.com/precisesale/app      latest              b7833546c2cf        About an hour ago ago   252.1MB             123.8MB             128.4MB             1
healthdiary/app                          latest              565c6d3906e6        2 days ago ago          312.2MB             123.8MB             188.4MB             1
mongo                                    latest              f93ff881751f        5 days ago ago          367.6MB             0B                  367.6MB             2
nginx                                    latest              b175e7467d66        6 weeks ago ago         108.9MB             0B                  108.9MB             1
jwilder/docker-gen                       latest              8959ee34c769        2 months ago ago        19.91MB             4.148MB             15.77MB             1
jrcs/letsencrypt-nginx-proxy-companion   latest              17939ceb7a52        2 months ago ago        86.86MB             4.148MB             82.71MB             1

Containers space usage:

CONTAINER ID        IMAGE                                    COMMAND                  LOCAL VOLUMES       SIZE                CREATED ago         STATUS              NAMES
c20dc3438552        healthdiary/app                          "./entrypoint.sh nod…"   0                   0B                  8 minutes ago ago   Up 8 minutes        healthdiary_app_1
bf8c4307dcbb        mongo:latest                             "docker-entrypoint.s…"   1                   0B                  8 minutes ago ago   Up 8 minutes        healthdiary_mongo_1
47fced8d18fe        registry.gitlab.com/precisesale/app      "./entrypoint.sh nod…"   0                   0B                  9 minutes ago ago   Up 9 minutes        precisesale_app_1
597d97d5c1fa        mongo:latest                             "docker-entrypoint.s…"   1                   0B                  9 minutes ago ago   Up 9 minutes        precisesale_db_1
b5bb14faa910        jwilder/docker-gen                       "/usr/local/bin/dock…"   0                   0B                  7 hours ago ago     Up 19 minutes       nginx-gen
8eee2bee084a        nginx                                    "nginx -g 'daemon of…"   0                   2B                  7 hours ago ago     Up 19 minutes       nginx-web
6b8b0cd5d938        jrcs/letsencrypt-nginx-proxy-companion   "/bin/bash /app/entr…"   0                   1.66kB              7 hours ago ago     Up 19 minutes       nginx-letsencrypt

Local Volumes space usage:

VOLUME NAME                                                        LINKS               SIZE
0a40fac6ca98e776dad972c8193362a51a485b3305979e58996545d97310a3c7   1                   0B
929b0b88849ad4d390efd4666e6a0e5f82e0e6dd34f7a09f609de90b190e6148   1                   0B

Build cache usage: 0B

Even if I do not take into account savings from shared space from two first containers summary size is 1147.5 MB

But if I measure size of docker overlay2 on disc by du I get

du -hs /var/lib/docker/overlay2/
2.7G    /var/lib/docker/overlay2/

Where is reason of difference in size of containers measured by docker system df and du?


Solution

  • I was wondering the same thing some time ago. It’s not a bug, it’s a feature :-)

    du -sh /var/lib/docker/overlay2
    

    is not showing objective value because merge folders have been mounted using overlay driver and du output is not actual disk allocation size.

    You can see the actual disk allocation size by examining only diff folders like:

    du -shc /var/lib/docker/overlay2/*/diff
    

    You can test this in your environment like this: run

    df -h /dev/sd*
    du -shc /var/lib/docker/overlay2/*/diff
    du -sh /var/lib/docker/overlay2
    

    Now start 20 centos containers and observe what has change:

    for i in {1..20}; do docker run -itd centos bash; done
    df -h /dev/sd*
    du -shc /var/lib/docker/overlay2/*/diff
    du -sh /var/lib/docker/overlay2
    

    You can see that the actual disk allocation (df command) is just cca 200MB more than before, but “du” on whole folder outputs 4.2G allocation. “du” on “diff” folders shows 212M what is correct.

    This is how Docker works and what makes it great!