When getting started with containers, it’s pretty easy to be shocked by the size of the images that we build. We’re going to review a number of techniques to reduce image size, without sacrificing developers’ and ops’ convenience. In this first part, we will talk about multi-stage builds, because that’s where anyone should start if they want to reduce the size of their images. We will also explain the differences between static and dynamic linking, as well as why we should care about that. This will be the occasion to introduce Alpine.
https://www.ardanlabs.com/blog/2020/02/docker-images-part1-reducing-image-size.html
Nice background info
Wow, I went in expecting to slam this article as Alpine/small image hype. But, it is actually an excellent run down of the issues in play!
Good articles. I’d have added at the beginning the basic explanation of why removing a big file as a dockerfile step doesn’t make the image smaller (hence we use build images to create run images)
I think that the last part of part 1 is missing the dockerfile, specifically the part with BusyBox:glibc
Excellent articles though.
Part 3 mentions DockerSlim… Looks like Jerome used the default config and the template files weren’t picked up. This example ( https://github.com/docker-slim/examples/tree/master/3rdparty/ubuntu-com ) shows how to do something similar with the container for ubuntu.com, which is a Python/Flask web app that leverages dynamic templates. Another option is to run a crawler when DS is optimizing the image.
Only thing to watch out for is that stuff can be kinda hardcoded to glibc sometimes and Alpine uses musl libc. For simple stuff Alpine is great though.
This is the second time I’ve said this in a week… I struggled with this myself recently and couldn’t find a definitive guide to help me through it, so brute forced my way through by trial and error, turning a 2.4 GB image in to a 80MB image that contained just the GoLang executable and assets (ca-root and tz-data)
Thank you for writing this, you will have saved future generations from the horror I went through.