问题
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:
- 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
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
- 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 setexperimental
toenable
. Example:{ "experimental": "enabled" }
. More info at official docs.Issue
docker manifest inspect -v <registry-domain>/<image-name>
and see add thesize
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:
- It's the compressed size of the layers, not their on-disk size on your server.
- If the image is a multi-arch image (e.g.
alpine
linux containsarm
,amd64
and several architectures), then you'll get the total of those while in actual usagedocker
only uses the relevantarch
.
回答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