Get the size of a Docker image before a pull?
How does one get the size of a Docker image before they pull it to their machine?
Solution 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.
Solution 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
.
Solution 3:
Docker Hub
Get the compressed size in bytes of an image specific tag.
# 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
Get the compressed size in bytes of an image tag for a specific architecture / os.
# 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
Alternative
An alternative is to use the experimental docker manifest inspect
command. The advantage is that it does not rely on Docker Hub, it works as well with other registries because it's based on the Image Manifest specification.
# 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