Download size of Docker images

Viewed 2048

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.

4 Answers

@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
      
Related