6

I pull a Docker image of about 0.5 GB in size on the Docker Hub. After pulling it on my Centos machine the size of the image became 1.6 GB. Pushing the image with a new name show 2 GB on the Docker hub. How can I obtain an image with the same size on the Docker hub?

3
  • 1
    Can you give more details? A reproducer? Dec 6, 2015 at 8:09
  • The sizes of tags listed on Docker Hub are the compressed size. The image is sent to you compressed and gets decompressed once pulled to your local server and will be much larger than listed.
    – Andy Shinn
    Dec 6, 2015 at 23:09
  • You can use github.com/wemake-services/docker-image-size-limit to check that size of your image is not getting too big.
    – sobolevn
    Mar 3, 2019 at 14:57

2 Answers 2

2

There are several ways to achieve that, depending on which repository you are querying.

TLDR; See this repo: schnatterer/docker-image-size.

Details:

The former two work for DockerHub and returned same size for the test image debian:stretch-20190204-slim on DockerHub:

Screenshot DockerHub

I didn't find a working solution for quay.io and for private Repos in general, yet.

docker manifest

Requires jq.

export DOCKER_CLI_EXPERIMENTAL=enabled

echo $(( ( $(docker manifest inspect -v docker.io/debian:stretch-20190204-slim \
              | jq '.[] | select(.Descriptor.platform.architecture == "amd64").SchemaV2Manifest.layers[0].size') \
           + 500000) \
         / 1000 \
         / 1000)) MB
23 MB

If you care about the details:

  • export DOCKER_CLI_EXPERIMENTAL=enabled - docker manifest is still considered experimental (as of 18.06.1-ce). Can be made permanent in ~/.docker/config.json - See docker manifest | Docker Documentation
  • docker manifest inspect -v docker.io/debian:stretch-20190204-slim - queries verbose manifest from docker hub
  • jq '.[] | select(.Descriptor.platform.architecture == "amd64").SchemaV2Manifest.layers[0].size - filters the compressed size of all layers (bytes)
  • + 500000 - for rounding
  • /1000 - divide to KB/MB

reg

Requires reg and jq.

➜ echo $(( ( $(reg manifest debian:stretch-20190204-slim |  \
            jq '.layers[].size' \
            | paste -sd+ | bc) \
           + 500000) \
         / 1000 \
         / 1000)) MB
23 MB

If you care about the details:

  • reg manifest debian:stretch-20190204-slim - queries manifest from docker hub
  • jq '.layers[].size' - filters the compressed size of each layer (bytes)
  • paste -sd+ | bc - creates a sum of the individual sizes (bytes)
  • + 500000 - for rounding
  • /1000 - divide to KB/MB

curl

reg and docker manifest didn't work out of the box for some other repos. Here, curl might be sufficient, however. This, OTOH, is a bit more difficult with docker hub (because we need a token).

➜ echo $(( ( $(curl -s https://gcr.io/v2/distroless/java/manifests/11-debug |  \
            jq '.layers[].size' \
            | paste -sd+ | bc) \
           + 500000) \
         / 1000 \
         / 1000)) MB
69 MB

Further Registry examples:

1

A similar issue was reported in issue 14204, for docker 1.7.0 on Ubuntu.
(And by default, CentOS might not have the latest version of docker, so the first step would be to upgrade if possible)

The questions to check were:

  1. How did you install docker?
  2. Can you provide the list the steps to reproduce the issue?
  3. Can you post the output from sudo du -sh /var/lib/docker/*
  4. You are using devicemapper as a storage driver, can you try using aufs?

For the last point, as described in this article, check /etc/default/docker

# Use DOCKER_OPTS to modify the daemon startup options.
DOCKER_OPTS="--storage-driver=devicemapper"

As the OP Dragomir Adrian confirms in the comments, it is a docker version issue: upgrading to 1.9.1 helps.

6
  • 1. yum install docker Dec 6, 2015 at 16:59
  • @DragomirAdrian what version of docker is installed with yum?
    – VonC
    Dec 6, 2015 at 17:30
  • 1. yum install docker Docker version 1.8.2, build bb472f0/1.8.2 Kernel version 3.10.0-229.20.1.el7.x86_64 2. - docker login - docker pull [image] Image size is 494 MB on the Docker public hub - docker images Image size is 1582 MB - create a private Docker repository - docker tag [image] username/[repository name] - docker push username/[repository name] On the Docker private repository I have now a image test with 2 GB size 3. 4. Storage drive is already devicemapper Dec 6, 2015 at 20:00
  • 1
    @DragomirAdrian OK. First, upgrade to the latest version of everything. Docker 1.9.1.
    – VonC
    Dec 6, 2015 at 20:01
  • Finally I upgraded to the 1.9.1 version and I repeated the procedure. The size of the Docker image is now correct, thank you. I still have a question: why it is shown I push 1.6 GB over the internet and the Docker image is 494 MB? Dec 7, 2015 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.