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?
-
1Can you give more details? A reproducer?– user2915097Dec 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 ShinnDec 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.– sobolevnMar 3, 2019 at 14:57
2 Answers
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:
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 Documentationdocker manifest inspect -v docker.io/debian:stretch-20190204-slim
- queries verbose manifest from docker hubjq '.[] | 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
➜ 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 hubjq '.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:
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:
- How did you install docker?
- Can you provide the list the steps to reproduce the issue?
- Can you post the output from sudo du -sh /var/lib/docker/*
- 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.
-
-
-
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.– VonCDec 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