Get the size of a Docker image before a pull?

2020-03-01 03:00发布

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

4条回答
乱世女痞
2楼-- · 2020-03-01 03:11
  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楼-- · 2020-03-01 03:15

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

查看更多
Summer. ? 凉城
4楼-- · 2020-03-01 03:21

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

查看更多
Juvenile、少年°
5楼-- · 2020-03-01 03:33

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.

查看更多
登录 后发表回答