bin*_*yDi 16
curl -s -H "Authorization: JWT " "https://hub.docker.com/v2/repositories/library/<image-name>/tags/?page_size=100" | jq -r '.results[] | select(.name == "<tag-name>") | .images[0].size' | numfmt --to=iec-i
Run Code Online (Sandbox Code Playgroud)
对于其他注册表(如 Microsoft Container Registry)上的镜像
将镜像推送到 Docker Hub,您可以在 Docker Hub 网站上获取镜像的压缩大小。
使用docker save保存图像到一个.tar文件,然后将其压缩.tar.gz文件。
docker save my-image:latest > my-image.tar
# Compress the .tar file
gzip my-image.tar
# Check the size of the compressed image
ls -lh my-image.tar.gz
Run Code Online (Sandbox Code Playgroud)
使用docker manifest inspect观察舱单数据,这说明你的压缩图像的大小。
您需要首先通过编辑~/.docker/config.json文件启用它并设置experimental为enable. 例子:{ "experimental": "enabled" }。更多信息请见官方文档。
发布docker manifest inspect -v <registry-domain>/<image-name>并查看size为层添加 ,但仅限于您的特定架构(例如amd64)。
docker manifest inspect -v <registry-domain>/<image-name> | grep size | awk -F ':' '{sum+=$NF} END {print sum}' | numfmt --to=iec-i
Run Code Online (Sandbox Code Playgroud)
著名的:
alpineLinux的包含arm,amd64和几个架构),那么你会得到总的,而在实际使用中docker只使用相关arch。Aks*_*jan 14
在Docker Hub上搜索Docker映像时,将有2个选项卡- Repo Info和Tags。打开标签选项卡,您将看到可以为该图像提取的所有图像类型的尺寸。
Dav*_* L. 14
在拉取任何服务Image Manifest V2的注册表之前获取压缩图像大小:
docker manifest inspect(在最近的 Docker 版本中默认可用)jqiec使用标准格式设置大小numfmt(不是si,清单中的大小基于1024)$ dockersize() { docker manifest inspect -v "$1" | jq -c 'if type == "array" then .[] else . end' | jq -r '[ ( .Descriptor.platform | [ .os, .architecture, .variant, ."os.version" ] | del(..|nulls) | join("/") ), ( [ .SchemaV2Manifest.layers[].size ] | add ) ] | join(" ")' | numfmt --to iec --format '%.2f' --field 2 | sort | column -t ; }
$ dockersize mcr.microsoft.com/dotnet/core/samples:dotnetapp-buster-slim
linux/amd64 72.96M
$ dockersize ghcr.io/ddelange/pycuda/runtime:3.9-master
linux/amd64 1.84G
linux/arm64 1.80G
$ dockersize python
linux/amd64 334.98M
linux/arm/v5 308.21M
linux/arm/v7 295.69M
linux/arm64/v8 326.32M
linux/386 339.74M
linux/mips64le 314.88M
linux/ppc64le 343.86M
linux/s390x 309.52M
windows/amd64/10.0.20348.825 2.20G
windows/amd64/10.0.17763.3165 2.54G
Run Code Online (Sandbox Code Playgroud)
apt-get install jqbrew install coreutils jq(coreutils 附带numfmt)获取图像特定标签的压缩大小(以字节为单位)。
# for an official image the namespace is called library
curl -s https://hub.docker.com/v2/repositories/library/alpine/tags | \
jq '.results[] | select(.name=="latest") | .full_size'
# 2796860
# here the project namespace is used
curl -s https://hub.docker.com/v2/repositories/jupyter/base-notebook/tags | \
jq '.results[] | select(.name=="latest") | .full_size'
# 187647701
Run Code Online (Sandbox Code Playgroud)
获取特定架构/操作系统的图像标签的压缩大小(以字节为单位)。
# selecting an architecture
curl -s https://hub.docker.com/v2/repositories/library/alpine/tags | \
jq '.results[] | select(.name=="latest") | .images[] | select (.architecture=="amd64") | .size'
# 2796860
# selecting an architecture and a specific os
curl -s https://hub.docker.com/v2/repositories/library/hello-world/tags | \
jq '.results[] | select(.name=="latest") | .images[] | select (.architecture=="amd64" and .os=="linux") | .size'
# 2529
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用实验docker manifest inspect命令。优点是它不依赖于 Docker Hub,它可以与其他注册表一起使用,因为它基于Image Manifest 规范。
# activate experimental mode
export DOCKER_CLI_EXPERIMENTAL=enabled
docker manifest inspect -v alpine:latest | \
jq '.[] | select(.Descriptor.platform.architecture=="amd64") | .SchemaV2Manifest.layers[].size'
# 2796860
# need to sum if multiple layers
docker manifest inspect jupyter/base-notebook:latest | \
jq '[.layers[].size] | add'
# 187647701
Run Code Online (Sandbox Code Playgroud)
小智 2
如果你真的研究了拉操作的docker代码,我想你的答案就在那里。如果容器的镜像没有被缓存,那么在拉取镜像的过程中,docker首先会从registry中收集镜像的信息,比如层数、每层的大小等。
我会参考阅读这个文件。
https://github.com/moxiegirl/docker/blob/master/distribution/xfer/download.go
| 归档时间: |
|
| 查看次数: |
6930 次 |
| 最近记录: |