Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 635
Joseph Idziorek Avatar asked Oct 26 '15 18:10

Joseph Idziorek


People also ask

How do I determine the size of a docker image?

To view the approximate size of a running container, you can use the command docker container ls -s . Running docker image ls shows the sizes of your images. To see the size of the intermediate images that make up your image use docker image history my_image:my_tag .

How do I determine the size of a docker layer?

Inspect the size of an imageThe docker image ls command not only lists image identifiers and names. Additionally, it shows the actual size of the entire image. If you don't have any image on your local machine, go ahead and pull an image of your choice from Docker Hub.

How can I tell when a docker image was pulled?

json file where docker stores images with their sha256 values. Find the image you are looking after and copy it's sha256 hash somewhere. Find the sha265 value you found in repositories. json then look at the date.

Which command will return the size on disk of a docker container?

The docker system df command displays information regarding the amount of disk space used by the docker daemon.


2 Answers

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.

like image 163
Akshay Mahajan Avatar answered Sep 23 '22 21:09

Akshay Mahajan


  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.
like image 21
binaryDi Avatar answered Sep 22 '22 21:09

binaryDi