This article will cover the basics to reduce the size of your Docker images.
Prerequisites ✅
Understanding of Docker: Here
An existin...
For further actions, you may consider blocking this person and/or reporting abuse
If you really need to shrink the size of a Docker image instead of Alpine you may want to use a distroless image. Moreover, if you have only one executable to dockerize and you don't need to emulate an OS environment, you can use the scratch image and run the executable as PID 1.
Will try that on next time!
Thank you so much for sharing :)
yeah, I have tried some of these approaches, the best result I got was with scratch, with that, service in go in docker is reduced to ~8mb (just the executable only), I did the same with Rust as well, and got that reduced even more AFAIR, if you use scratch as the base image(scratch means empty, IE you only pack the executable to the docker image, that essentially means, it's mostly upto the compiler to reduce the executable size, with go and Rust, it is easy to do), you will have to cross compile and both go and Rust has compiler flags to do that
That's great! Thanks Rajith for sharing this insight.
Hope this article helped :)
Also, one of the most neglected part is to condensate run statement, if you have 10 command to execute, running them all in a single RUN will create only one layer, bonus point if some of those command create temporary files, you can erase them at the end of that RUN, they won't be present at all in the final image. In particular Linux update can get a major gain since you can delete the package cache, index and the repo index that are totally useless once the update is completed.
Will give it a try!
Hey @kitarp29
I have heard that using lighter base images like alpine are not official, also they are not well tested, so is it really safe to use these images in production?
Or should I use other methods to reduce image size?
Don't use unofficial images in Production ever!
You can introduce a job in your CI pipeline to scan for vulnerabilities in your Docker images.
Some of the tools that help you with this are:
You can also achieve that by using a container registry, which can automatically compress images, hence reducing their size.
Reducing the size of a Docker image helps massively reducing the download time and much less storage, which is the main idea of your article.
Great article in general, fellow writer @kitarp29!👏
Thanks Bruno! I will keep that in mind.
Your kind words means a lot ot me :)
Amazing post Pratik.
Thank you Pavan
Thank you for the article! Just curious which is slim reduction of Docker to make this big difference size?
Great post, it would be helpful if you included some stats like how much time it took to spin container with older and newer image.
Veeresh I don't have the exact metric for it. But safe to assume it takes atleast half of the time.
"Further reduced the size of the binary further and finally got a size of around 16 MB."
What steps did you take for this further reduction in image size?
Well this article tells the entire story of it.
You can read more about it in this Twitter thread I was a part of:
twitter.com/sidpalas/status/163783...
We're about to do this with the images we build at work, so this is very timely.
I am glad I could help :)
Thanks for reading my article 😃
Great article🔥
Thanks 😌
Very practical advice. Thank you.
Thanks :)
Hope it helps!
Really insightful Blog Pratik
Thanks! Hope it helped :)
Quite insightful Pratik, thanks for sharing!
Thanks Nikki!
Hope it helps 😊