3 ways to reduce the size of your docker images

preview_player
Показать описание
Learn the 3 most powerful ways to reduce the size of your Docker images.

If you're reading this, chances are you have felt the pain of massively bloated Docker images which take up several GBs worth of space on disk and over Network bandwidth. They slow down deployments, increase costs and make the whole development process much slower and frustrating!

In this video, I'll discuss powerful image size reduction techniques such as Multistage builds, layer-level optimization and Scratch images. We'll also go through some best practices and I'll show you how I brought a 1GB Docker image down to just 8 MB!

These will help you get rid of image bloat and can potentially save you thousands of $$

Learn Docker & Kubernetes with me for FREE! 👉

TIMESTAMPS ⏰
00:00 Intro
00:23 Multistage builds
08:29 Layer optimization
11:58 Images From Scratch
15:45 Other techniques

👉 REFERENCES

👉 ABOUT ME

#docker #optimization
Рекомендации по теме
Комментарии
Автор

to be honest this is a subject I never thought I should have done, thank you, this was great and very helpful

achaabni
Автор

Nice video, i have followed the same steps a year ago while building a container image for deploying it in AWS lambda. But scratch is a new thing i learned today.
And storing an already built tools in an external storage like s3 is a great way to improve the build time of the docker image, i have uploaded static binary of ffmpeg and dynamically linked binaries of poppler-utils package for improving build times.

MahendraKondadasu-jn
Автор

At 9:46 I'm pretty sure that the duration was actually 75.4 seconds as can be seen at the top, or 76.18 seconds (aka 1 minute 16.18 seconds) as measured by time command. The 0.47s user means that only half a second was spent in userland or something like that. And we can see that it takes 266 MB in size.

And at 11:20 we can see that the one-layer build took 71.8 seconds as measured by docker or 72.38 seconds as measured by time. So 3-4 seconds faster, which is not much, but it's still a gain. The multi-layer docker build also didn't had THAT many instructions to begin with. If you have a 30 instruction builds (I've seen them) I think it should help more.
The size of the single-layer build can also be seen that is at 262 MB, which is only 4 MB lower than the multi-layer one.

To be frank, I kind of don't understand why multiple layers would need more space (except some minimal space needed for the layers and its metadata, which should be negligible).
However, if I'm not mistaken, having less / fewer layers has other benefits, like faster i/o in general for the docker build, since something like a find command run inside the container should not check multiple layers, aka multiple file systems. So while the build time and space might not be much better from the single-layer build, it should run faster/better, and should be enough of a reason to do it.

The scratch idea is pretty neat, totally didn't thought about that one. Good mention that you don't have bash and probably not even things like cd, ls and so on. For something like php which is the main thing I use, I'm not sure how easy to do would be and especially how useful. I also I'm not so sure what is the difference between simply running that executable directly on the host.

Also, it might've been nice to show the contents of the images in the different scenarios. But it's a very nice video, decently detailed and very on point. Keep it up!

Winnetou
Автор

Thanks raghv dua for your informative tutorial on reducing docker image size

mohammadanas
Автор

apt-get is the legacy way. Just using apt update and upgrade will fetch latest repo metadata and upgrades. You can use docker init to create multistage and multilayer builds with caching. Another alternative is to use distroless images from Google container or passenger if you want very minimal Ubuntu base image of 8MB.

vasudevmenon
Автор

this was amazing!
please do another video for reducing build time

sk
Автор

Amazing content, please can you make videos on how we can deploy docker on server?

alexdin
Автор

It's work well for compile languages like go lang, java, but what about nodejs ? Alpine also having its own limitations for http protocol which is dependent upon c++ package less performance

sanjaydns
Автор

This is interestinig approach. Can we call multi-stage builds as pre-processed builds?

pbdivyesh
Автор

Hope you guys learnt something interesting from this video 🙂
Creating good quality content while also having a Day Job is hard - I mostly spend nights and weekends doing this stuff.
So I'm also looking for another person who could take out some time and help me with the content (obviously, this comes with perks 😉)

sre
Автор

Which tool do you use for creating these flow diagrams ??

gangadharmatta
Автор

Hi
Iam unable to use a python(pytest) based script using python-alpine image, any idea

BeingNormal-xv
Автор

Any Solution how to reduce compile time in development in nextjs?

avijitpal
Автор

Is it good practice to use alpine in production?

snsbdccRJccb-ykyw
Автор

How it should work with runtime dependency

relaxspacee
Автор

Great video. Wasn't aware about Scratch. TIL

AshishKumar-qigk
Автор

Do people include source code and build tools in their final images??? I don't think it's common.

PaulBunkey
Автор

how about node js? what we all know, node js is interpreter language, than means we still need all node modules, different from golang, we can remove all pre build file, cause we just need executable file

rusliabdulgani
Автор

How it would be for a Django project or Fastapi project?

luismex
Автор

Mirror your face cam so you are looking inside the video, not out of the video.

ayushchothe