After I wrote my previous post, some suggested that I can cut down the image size further by using a “scratch” image. And that’s true, “scratch i"s a reserved 0-sized image with nothing in it. And utilizing a scratch binary image did cut down the size of the final Docker image from 13MB to 7.5MB. Pretty good, right? Except the image cannot do an SSL cert verification because of the missing SSL certs!!!
|
|
The fix was relatively easy.
Build ca-certificates
in the builder phase.
Another thing to add during the builder phase is the timezone data.
|
|
And copy these over in the run phase.
|
|
The final image is about 0.2 MB larger, and the problem is fixed. See the final code here.
But, what else is in the 5 MB alpine docker image?
The images are from https://github.com/alpinelinux/docker-alpine and check its content. There are tons of standard shell utilities like “ls” symlinked to “busybox”, alpine package database (/apk), other standard libraries for C, SSL. Here are the biggest contributors to size.
|
|
I think it is OK to use scratch as long as you are building a static binary and copying root certificates. I, personally, feel that it’s better to use a 5MB larger alpine Linux image with no surprises.