Introduction
In a previous post, we shared details of an analysis we conducted to optimize our container’s image sizes in order to improve our end users' experience. After some work, on September 9, 2022, we enabled the --squash option when building the container’s images, and we are already seeing some improvements.Changes at DockerHub
Here are the size reductions we observed for both assets:
- Pytorch: 46.9% reduction for the compressed size and 47.7% for the decompressed size
- Magento: 32.2% reduction for the compressed size and 34.64% for the decompressed size
How will end users see the benefits of this change?
End users can easily check the benefits of the improvements when they try to use the container’s images. We did a quick test by pulling the mentioned non-squashed and the squashed ones to see how much time the test needed. The script used for the test was this simple one:#!/bin/bash
docker system prune -a -f
start_time=$SECONDS
non_squashed_images=(bitnami/magento:2.4.5-debian-11-r9 bitnami/pytorch:1.12.1-debian-11-r10)
for image in "${non_squashed_images[@]}"
do
docker pull $image
done
non_squashed_elapsed=$(( SECONDS - start_time ))
docker system prune -a -f
start_time=$SECONDS
squashed_images=(bitnami/magento:2.4.5-debian-11-r10 bitnami/pytorch:1.12.1-debian-11-r11)
for image in "${squashed_images[@]}"
do
docker pull $image
done
squashed_elapsed=$(( SECONDS - start_time ))
echo "Time pulling non-squashed images: $non_squashed_elapsed s"
echo "Time pulling squashed images: $squashed_elapsed s"
Total reclaimed space: 0B
2.4.5-debian-11-r9: Pulling from bitnami/magento
3b5e91f25ce6: Pulling fs layer
… … …
… … …
Digest: sha256:bbdde3cea27eaec4264f0464d8491600e24d5b726365d63c24a92ba156344024
Status: Downloaded newer image for bitnami/magento:2.4.5-debian-11-r9
docker.io/bitnami/magento:2.4.5-debian-11-r9
1.12.1-debian-11-r10: Pulling from bitnami/pytorch
3b5e91f25ce6: Already exists
Digest: sha256:1a238c5f74fe29afb77a08b5fa3aefd8d22c3ca065bbd1d8a278baf93585814d
Status: Downloaded newer image for bitnami/pytorch:1.12.1-debian-11-r10
docker.io/bitnami/pytorch:1.12.1-debian-11-r10
Deleted Images:
untagged: bitnami/magento:2.4.5-debian-11-r9
untagged: bitnami/magento@sha256:bbdde3cea27eaec4264f0464d8491600e24d5b726365d63c24a92ba156344024
… … …
… … …
deleted: sha256:7ec26d70ae9c46517aedc0931c2952ea9e5f30a50405f9466cb1f614d52bbff7
deleted: sha256:d745f418fc70bf8570f4b4ebefbd27fb868cda7d46deed2278b9749349b00ce2
Total reclaimed space: 3.415GB
2.4.5-debian-11-r10: Pulling from bitnami/magento
3b5e91f25ce6: Pulling fs layer
Digest: sha256:7775f3bc1cfb81c0b39597a044d28602734bf0e04697353117f7973739314b9c
Status: Downloaded newer image for bitnami/magento:2.4.5-debian-11-r10
docker.io/bitnami/magento:2.4.5-debian-11-r10
1.12.1-debian-11-r11: Pulling from bitnami/pytorch
3b5e91f25ce6: Already exists
Digest: sha256:3273861a829d49e560396aa5d935476ab6131dc4080b4f9f6544ff1053a36035
Status: Downloaded newer image for bitnami/pytorch:1.12.1-debian-11-r11
docker.io/bitnami/pytorch:1.12.1-debian-11-r11
Total reclaimed space: 1.947GB
Time pulling non-squashed images: 165 seconds
Time pulling squashed images: 91 seconds
- The uncompressed size dropped from 3.415GB to 1.947GB (43% less).
- Squashed images pulling was 45% faster than the normal ones.
- The base image layer with digest 3b5e91f25ce6 used always from the cache in the second pull (for non-squashed and squashed ones).
- Non-squashed:
- bitnami/wordpress:6.0.2-debian-11-r2
- bitnami/mariadb:10.6.9-debian-11-r7
- Squashed:
- bitnami/wordpress:6.0.2-debian-11-r3
- bitnami/mariadb:10.6.9-debian-11-r8
#!/bin/bash
docker system prune -a -f
start_time=$SECONDS
docker-compose -f wordpress-docker-compose-non-squashed.yml up -d
non_squashed_elapsed=$(( SECONDS - start_time ))
docker-compose -f wordpress-docker-compose-non-squashed.yml down
docker system prune -a -f
start_time=$SECONDS
docker-compose -f wordpress-docker-compose-squashed.yml up -d
squashed_elapsed=$(( SECONDS - start_time ))
docker-compose -f wordpress-docker-compose-squashed.yml down
docker system prune -a -f
echo "Time pulling and starting non-squashed WordPress: $non_squashed_elapsed s"
echo "Time pulling and starting squashed WordPress: $squashed_elapsed s"