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?
The maximum size for a deployable container image on Azure Container Instances is 15 GB.
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.
The reason behind this is that docker would be able to cache the image with the required dependencies, and this cache can then be used in the following builds when code gets modified.
Docker images are a core component in our development and production lifecycles. Having a large image can make every step of the process slow and tedious. Size affects how long it takes to build the image locally, on CI/CD, or in production and it affects how quickly we can spin up new instances that run our code.
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.
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 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/MBRequires 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 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/MBreg
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With