Queries and compares docker image sizes.
506
Queries and compares docker image sizes.
See also this blog post.
Most convenient: don't install at all; just run docker container (see usage). You can use it even more convenient by establishing an alias
alias docker-image-sizes='docker run --rm -e DIS_IMPL schnatterer/docker-image-size'
# If you want to query the size of a single image (faster)
# e.g. using curl (alternatives: docker, reg)
alias docker-image-size='docker run --rm --entrypoint docker-image-size-curl.sh schnatterer/docker-image-size'
Note that the image is cached locally, if you ever want to "update", just do a
docker pull schnatterer/docker-image-size
jq, e.g sudo apt get install jqsudo ln -s $(pwd)/scripts/docker-image-size-docker.sh /usr/local/bin/docker-image-size-docker.sh
sudo ln -s $(pwd)/scripts/docker-image-size-curl.sh /usr/local/bin/docker-image-size-curl.sh
sudo ln -s $(pwd)/scripts/docker-image-size-reg.sh /usr/local/bin/docker-image-size-reg.sh
sudo ln -s $(pwd)/scripts/docker-image-sizes.sh /usr/local/bin/docker-image-sizes
Note the execution might take minutes (depending on the number of tags to query), because docker manifest is
infamously slow. You can use other implementations that might be less compatible with some repos,
though.
docker run --rm schnatterer/docker-image-size <docker image name> [<extended grep regex on docker tag>]
# Or with the alias mentioned above:
docker-image-sizes <docker image name> [<extended grep regex on docker tag>]
docker-image-sizes <docker image name> [<extended grep regex on docker tag>]
# or from repo
scripts/docker-image-sizes.sh <docker image name> <extended grep regex on docker tag>
If you care about size of one image only you can use the implementations directly, which for the
curl implementation responds in about a second. Note that it takes only one parameter, similar to docker run:
# e.g. using curl (alternatives: docker, reg)
$ docker-image-size-curl.sh <docker image name>[:<Tag> | @<RepoDigest>]
# Or using the docker image
$ docker run --rm --entrypoint docker-image-size-curl.sh schnatterer/docker-image-size <docker image name>[:<Tag> | @<RepoDigest>]
# Match all tags containing '11' (a whole lot. Will take ages!)
docker-image-sizes adoptopenjdk 11
# More accurate (and faster) output
docker-image-sizes adoptopenjdk '^11.0.4'
# Multi arg results can be filtered using grep
docker-image-sizes adoptopenjdk '^11.0.4' | grep 'amd64 linux'
# Query a single image (fastest!)
docker-image-size-curl.sh adoptopenjdk:11.0.4_11-jre-hotspot
docker-images-sizes.sh can use different implementations for querying the docker manifest from the repos. See
Features per implementation bellow for details.
By default docker-images-sizes.sh uses docker (the docker manifest command), but you could switch to curl or
reg as follows:
docker run --rm -e DIS_IMPL=curl schnatterer/docker-image-size <docker image name> [<extended grep regex on docker tag>]
DIS_IMPL=curl docker-image-sizes <docker image name> [<extended grep regex on docker tag>]
Depending on the registry you query from, not all implementations might work.
See unit tests for more details.
| curl | docker | reg | |
|---|---|---|---|
| with/without tag | ✔️ | ✔️ | ✔️ |
| repo digest | ✔️ | ✔️ | ✔️ |
| platform-specific digest | ✔️ | ❌ | ❌ |
| private repos | ❌ | ✔️ | ️✔️ |
| multi-arch | ❌ | ✔️ | ️❌ |
| manifest v1 | ❌ | ❌ | ❌ |
| speed | fastest | slowest️ | ️in between️ |
| docker hub | ✔️ | ✔️ | ✔️ |
| gcr.io | ✔️ | ✔️ | ✔️ |
| r.j3ss.co | ️️✔️ | ️✔️ | ✔️ |
| quay.io | ✔️ | ✔️ | ❌️ |
| mcr.microsoft.com | ❌ | ✔️ | ❌ |
Queries with the experimental docker manifest command.
A bit slower than the others but best compatibly for repos and most features (e.g. multi-arch). Requires docker.
# This repo only works with -docker.sh
$ scripts/docker-image-size-docker.sh mcr.microsoft.com/windows/servercore:1903
mcr.microsoft.com/windows/servercore:1903 amd64 windows 10.0.18362.356: 2217 MB
Tested with docker 19.03.2
Queries with plain curl. Fastest, fewest requirements, but also least features (e.g. no private repos, no multi-arch).
$ scripts/docker-image-size-curl.sh gcr.io/distroless/java:11-debug
gcr.io/distroless/java:11-debug: 73 MB
# Does not work with reg v0.16.0
$ scripts/docker-image-size-curl.sh quay.io/prometheus/prometheus:v2.12.0
quay.io/prometheus/prometheus:v2.12.0: 55 MB
Tested with
Queries with genuinetools/reg. A compromise in terms of speed and features but supports fewest registries.
Requires either reg installed or docker.
$ scripts/docker-image-size-reg.sh docker.io/debian:stretch-20190204-slim
docker.io/debian:stretch-20190204-slim: 23 MB
If you're using reg via docker, you can update to the latest version with
docker pull r.j3ss.co/reg
Tested with reg version: v0.16.0; git hash: f180c93a.
docker-image-size-*.sh scripts, see
scripts.tags command) allows for querying docker image tags on the
command line.$ docker run r.j3ss.co/reg tags maven | grep -e '^3.6.2' | \
xargs -I{} scripts/docker-image-size-curl.sh "maven:{}"
maven:3.6.2: 320 MB
maven:3.6.2-amazoncorretto-11: 338 MB
#...
docker-image-size-docker.sh in order to avoid
errors and get more details. Unfortunately, it's much slower:
$ docker run r.j3ss.co/reg tags adoptopenjdk | grep -e '^11.0.4' \
| xargs -I{} scripts/docker-image-size-docker.sh "adoptopenjdk:{}"
openjdk:11.0.4-jdk amd64 linux : 311 MB
openjdk:11.0.4-jdk arm64 linux : 303 MB
openjdk:11.0.4-jdk amd64 windows 10.0.17763.737: 2353 MB
openjdk:11.0.4-jdk amd64 windows 10.0.17134.1006: 2536 MB
openjdk:11.0.4-jdk amd64 windows 10.0.14393.3204: 5919 MB
# ...
export DEBUG=true # Results in set -x
scripts/docker-image-size-reg.sh docker.io/debian:stretch-20190204-slim
unset DEBUG
Content type
Image
Digest
Size
29.7 MB
Last updated
over 6 years ago
docker pull schnatterer/docker-image-size