Ravexina
Ravexina

Reputation: 2848

Download size of Docker images

While pulling a Docker image, it downloads it in separate parts (layers). I need to get the download size of all necessary layers of an image before actually downloading it.

Is there a way to do it?


One can just be running the docker pull command and watch the output:

ffcacfbccecb: Downloading [+++++>    ] 14.1 MB/30.13 MB
ffcdbdebabbe: Downloading [++>       ] 1.1 MB/12.02 MB

So its download size is "42.15".

However I've got some options enabled to download layers one by one:

ffcacfbccecb: Downloading [+++++>    ] 14.1 MB/30.13 MB
ffcdbdebabbe: Waiting

So this solution doesn't work for me.

Upvotes: 6

Views: 2976

Answers (4)

EACUAMBA
EACUAMBA

Reputation: 621

you can go to Docker Page, exemple: MySQL Container Tags as you can see in this image strong text I hope it help you and other ones.

Upvotes: 1

binaryDi
binaryDi

Reputation: 2131

@Andy's way is perfect. Thanks a lot! That does help me out.

  1. In reference to his answer, I use the below command to get the compressed size of a Docker image hosted 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
    
  2. For an image on another registry, like Microsoft Container Registry, I figured out three ways:

    • Use docker manifest inspect to observe the manifest data, which can give you idea on how to gain the compressed size of the image.

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

      To enable docker manifest inspect, edit ~/.docker/config.json file and set experimental to enable.(Reference: Docker manifest inspect)

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

    • Use docker save to save an 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
      

Upvotes: 2

Andy Shinn
Andy Shinn

Reputation: 28523

Unfortunately, the Docker Hub API isn't documented publicly. But you can get a JWT to use for the API and then make a call to list out the tags to get the size. Here is an example using jq to parse out the size in bytes:

First authenticate to get your token:

export HUBUSER=andyshinn
export HUBPASS=mypass
export HUBTOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${HUBUSER}'", "password": "'${HUBPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)

Now you can query the tags API to filter for a specific tag and get the size. In this example, we are getting the official library wordpress image and filtering out the latest tag:

curl -s -H "Authorization: JWT ${TOKEN}" "https://hub.docker.com/v2/repositories/library/wordpress/tags/?page_size=100" | jq -r '.results[] | select(.name == "latest") | .images[0].size'

You should get back something like 169817871 which is the size of the entire image in bytes. This is a modified example from information found at https://gist.github.com/kizbitz/e59f95f7557b4bbb8bf2.

Upvotes: 4

Ayushya
Ayushya

Reputation: 10447

However the answer provided by @Andy is more like a programmers' choice and a better way to do it. I usually use another way which I find easier and convenient.

I often use an online lab for testing the size and performance of Docker-image. My favorite is play-with-docker, which provides a terminal session of about 3 hours and you are free to do anything. Images get downloaded easily and very fast there. And after that I get all the information I require regarding the image, be it size or anything else. I can also see if that image suits my work or not by using it then and there.

Upvotes: 0

Related Questions