Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download size of Docker images

Tags:

docker

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.

like image 527
Ravexina Avatar asked Jun 29 '17 20:06

Ravexina


People also ask

What is the size of Docker image?

On the Docker Hub website the base image is listed as 29 MB. When the child image is built it downloads and installs Python, making it grow larger. Besides using Alpine base images, another method for reducing the size of your images is using multistage builds.

Can you download a Docker image?

To download the Docker image, complete the following steps: Log on to the Fix Central web site by using necessary credentials. Load the Docker image into registry using the downloaded image file by running the following command. Invoke the docker images command to verify if the image is loaded successfully.

Why are Docker images so small?

A Docker image takes up more space with every layer you add to it. Therefore, the more layers you have, the more space the image requires. Each RUN instruction in a Dockerfile adds a new layer to your image. That is why you should try to do file manipulation inside a single RUN command.

Why is Docker image so large?

Docker doesn't know what changes have happened inside a layer, only which files are affected. As such, this will cause Docker to create a new layer, replacing all those files (same content as /opt/jboss/wildfly/ but with with new ownership), adding hundreds of megabytes to image size.


1 Answers

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.

like image 189
Andy Shinn Avatar answered Oct 01 '22 02:10

Andy Shinn