TLDR
尺寸由下式给出docker images
is the 未压缩的大小安装的映像的locally,你只能得到从注册表的大小压缩图像(对于每个架构以及如果您想要每个层)。
来自本地图像
尺寸由下式给出docker images
is the 系统上图像的未压缩大小.
# getting the size of alpine:latest
docker images alpine:latest --format "{{.Repository}}:{{.Tag}} -> {{.Size}}"
# alpine:latest -> 5.57MB
如果您下载图像,您可以获得相同的信息locally
通过使用docker inspect
命令。
docker inspect alpine:latest | jq '.[].Size'
# 5573013
从注册表
据我所知你只能得到来自注册表的图像的压缩大小.
curl -s https://hub.docker.com/v2/repositories/library/alpine/tags/ | \
jq '.results[] | select(.name=="latest") | .full_size'
# 2796860
事实上,注册表可以给出图像的大小每个架构.
curl -s https://hub.docker.com/v2/repositories/library/alpine/tags/ | \
jq '.results[] | select(.name=="latest") | .images[] | {architecture: .architecture, size: .size}'
# {
# "architecture": "arm",
# "size": 2405675
# }
# {
# "architecture": "arm",
# "size": 2601912
# }
# {
# "architecture": "386",
# "size": 2791407
# }
# {
# "architecture": "s390x",
# "size": 2565829
# }
# {
# "architecture": "ppc64le",
# "size": 2803218
# }
# {
# "architecture": "amd64",
# "size": 2796860
# }
# {
# "architecture": "arm64",
# "size": 2706555
# }
您甚至可以获取详细信息每层的压缩大小通过使用docker manifest inspect
实验命令。
# activate experimental mode
export DOCKER_CLI_EXPERIMENTAL=enabled
docker manifest inspect -v alpine:latest | \
jq '.[] | select(.Descriptor.platform.architecture=="amd64") | .SchemaV2Manifest.layers[].size'
# 2796860
如果有多个层,您可以将它们相加。这是一个例子jupyter/base-notebook:latest
# getting the size through the API
curl -s https://hub.docker.com/v2/repositories/jupyter/base-notebook/tags | \
jq '.results[] | select(.name=="latest") | .full_size'
# 187647701
# summing each layer
docker manifest inspect jupyter/base-notebook:latest | jq '[.layers[].size] | add'
# 187647701