Get the size of a Docker image before a pull?

*爱你&永不变心* 提交于 2020-03-13 06:57:07

问题


How does one get the size of a Docker image before they pull it to their machine?


回答1:


When you search for a docker image on Docker hub, there will be 2 tabs- Repo Info and Tags. Open Tags tab and you will see the sizes of all the types of images you can pull for that image.




回答2:


  1. For image on Docker Hub:
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
  1. For images on other registry like Microsoft Container Registry

    • Push the image to Docker Hub and you can get the compressed size of the image on Docker Hub website.

    • Use docker save to save image to a .tar file and then compress it a .tar.gz file.

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
  1. To manually view the manifest data

Use docker manifest inspect to observe the manifest data, which shows you the compressed size of the image.

  • You need to first enable it by editing ~/.docker/config.json file and set experimental to enable. Example: { "experimental": "enabled" }. More info at official docs.

  • Issue docker manifest inspect -v <registry-domain>/<image-name> and see add the size for the layers but only for your specific architecture (e.g. amd64).

docker manifest inspect -v <registry-domain>/<image-name> | grep size | awk -F ':' '{sum+=$NF} END {print sum}' | numfmt --to=iec-i

Noted:

  1. It's the compressed size of the layers, not their on-disk size on your server.
  2. If the image is a multi-arch image (e.g. alpine linux contains arm, amd64 and several architectures), then you'll get the total of those while in actual usage docker only uses the relevant arch.



回答3:


Docker images have many layers so the total image size will depend on how many layers your image is using.

A good tool to visualize your images and it's layers (including total size) in your docker registry is this Image Layers from Century Link Labs

Github: imagelayers-graph




回答4:


If you really look into the docker code for pull operation, I think your answer is there. If the image of the container is not cached, then during pulling of the image, docker first collects the information about the image from the registry like number of layers, size of each layers etc. etc.

I would refer to read this file.

https://github.com/moxiegirl/docker/blob/master/distribution/xfer/download.go



来源:https://stackoverflow.com/questions/33352901/get-the-size-of-a-docker-image-before-a-pull

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!