docker 容量统计

镜像大小

$ docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
foonathan/micro_cpp_gcc   latest              a7f7b545ecc9        4 days ago          205MB
centos                    latest              67fa590cfc1c        2 weeks ago         202MB
alpine                    latest              961769676411        2 weeks ago         5.58MB
ubuntu                    18.04               a2a15febcdf3        3 weeks ago         64.2MB
ubuntu                    latest              a2a15febcdf3        3 weeks ago         64.2MB
ubuntu                    16.04               5e13f8dd4c1a        6 weeks ago         120MB
ubuntu                    14.04               2c5e00d77a67        3 months ago        188MB
centos                    7.4.1708            9f266d35e02c        5 months ago        197MB

其中 SIZE 字段即容器镜像的大小。

容器大小

$ docker ps -s
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES               SIZE
4658613cfbbe        alpine              "/bin/sh"           36 minutes ago      Up 36 minutes                           nervous_rosalind    22.7MB (virtual 28.3MB)
d3ec136444e9        ubuntu:18.04        "/bin/bash"         48 minutes ago      Up 48 minutes                           heuristic_moser     45MB (virtual 109MB)
7e3937a94ff2        alpine              "/bin/sh"           16 hours ago        Up 16 hours                             happy_lumiere       5.59GB (virtual 5.6GB)

其中 SIZE 字段中包含两个数值,括号之前的为容器可写层的大小,括号内的为容器总的(即容器镜像加上容器可写层)大小。

完整的容量统计

$ docker system df --verbose
Images space usage:

REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE                SHARED SIZE         UNIQUE SIZE         CONTAINERS
foonathan/micro_cpp_gcc   latest              a7f7b545ecc9        4 days ago          205.2MB             0B                  205.2MB             0
centos                    latest              67fa590cfc1c        2 weeks ago         201.9MB             0B                  201.9MB             0
alpine                    latest              961769676411        2 weeks ago         5.577MB             0B                  5.577MB             2
ubuntu                    18.04               a2a15febcdf3        3 weeks ago         64.18MB             0B                  64.18MB             1
ubuntu                    16.04               5e13f8dd4c1a        6 weeks ago         120.3MB             0B                  120.3MB             0
ubuntu                    14.04               2c5e00d77a67        3 months ago        188.2MB             0B                  188.2MB             0
centos                    7.4.1708            9f266d35e02c        5 months ago        196.6MB             0B                  196.6MB             0

Containers space usage:

CONTAINER ID        IMAGE               COMMAND             LOCAL VOLUMES       SIZE                CREATED             STATUS              NAMES
4658613cfbbe        alpine              "/bin/sh"           0                   22.7MB              39 minutes ago      Up 39 minutes       nervous_rosalind
d3ec136444e9        ubuntu:18.04        "/bin/bash"         0                   45MB                51 minutes ago      Up 51 minutes       heuristic_moser
7e3937a94ff2        alpine              "/bin/sh"           0                   5.93GB              16 hours ago        Up 16 hours         happy_lumiere

Local Volumes space usage:

VOLUME NAME         LINKS               SIZE

Build cache usage: 0B

CACHE ID            CACHE TYPE          SIZE                CREATED             LAST USED           USAGE               SHARED

可以看到,这里的 SIZE 是容器可写层的大小。

参考资料

How to analyze disk usage of a Docker container

https://stackoverflow.com/questions/26753087/how-to-analyze-disk-usage-of-a-docker-container

Explain the SIZE column in “docker ps -s” and what “virtual” keyword means

https://github.com/docker/docker.github.io/issues/1520#issuecomment-305179362


最后修改于 2019-09-07