Lightweight UPX docker image
docker run --rm -w $PWD -v $PWD:$PWD quay.io/kkh913/upx:latest --best --lzma -o app.out ./app
Reducing the size of the container image allows agile service deployment and spatial-efficient image registry management. To do this, here are two things:
-
Use of lightweight base image
It is common to distribute binary files inside a container as static-linked to remove dependencies. In our case, using a scratch image is more advantageous than the well-known default images busybox and alpine.
-
Reduced executable file size
UPX is the most well-known executable file packer. Since the compression ratio is usually significant between 50% ~ 70%.
โ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
quay.io/kkh913/upx latest 6b16e64aceaa 17 minutes ago 428kB
gruebel/upx latest 3c533895a64b 3 years ago 1.7MB
lalyos/upx latest 6fdc9a8475ac 5 years ago 1.15MB
As a result, there is only a difference in container size - negligible(๐ค) . And, each docker-upx has the same compression ratio and performance. But, I think that many drops make a shower in our container clusters.
- Single stage Build
- ADD his own static-linked upx released on GitHub
- Packing
- Fixed version 3.91
- Multi stage build
- 1st stage
- build his own static-linked upx
- 2nd stage
- copy upx to busybox
- 1st stage
- Dynamic version -> dev = latest but unstable
- Multi stage build
- 1st stage
- Find official latest release upx using GitHub API and download it
- 2nd stage
- Extract *.tar.xz
- 3rd stage
- Copy upx to scratch
- 1st stage
- No packing process
- Official release is already packed
- Dynamic version -> latest and stable