Also when I use dive to inspect the image then the step for
every single COPY command. It shouldnât get pass 180MB.
So why the final image is 926MB
I just donât understand why. This is maybe not a fault but I just donât get why it is like that. Distroless should make our container way more lighter. Right?
Yeah⊠no luck on finding improvement. But thanks to
I did find that the docker file is not the problem. The problem is I try to run PHP and NodeJS in the same distroless image. It goes against distroless fundamentals so thatâs why itâs so large in size. The only way is trying to separate or change the architecture of my code
Hereâs what I do to reduce the docker image size which you can give it a try at your end
Approach 1: Use of --no-install-recommends install in apt.
You can avoid installation of recommended packages by included the flag --no-install-recommends when using APT in your Dockerfile. Eg
RUN apt-get update && apt-get -y --no-install-recommends install \
Note: this could result in some missing libraries in your application image which you may have to add back explicitly, but this will ultimately give you more control in the dependencies in your project.
Approach 2: remove downloaded files from apt during installation to reduce docker image size
RUN rm -rf /var/lib/apt/lists/*
Maybe you can also save using more light weight images like alpine linux or so depending on your use-case
You probably meant removing the apt cache in the same instruction where the installation happens. Otherwise it will not affect the image size as it will just create a new layer hiding the files, but not removing them.
Also in this specific case that this topic was about, there was no apt install in the final stage so apt could not affect that stage at all. It was still a good general advise.