Why should we not simply use the instruction "RUN apt-get update && apt-get -y install
" in our Dockerfile? 👨🏻💻
To avoid the installation of recommended packages and to reduce the size of your Docker image, we should include the flag "--no-install-recommends
" when using APT in our Dockerfile.
Command "apt-get install" installs packages. To install those packages, it needs to download them.
Using --no-install-recommends tells apt-get to not install "recommended packages."
For example, if you install Vim, many plugins are also recommended and provided as separate packages. With that switch, those Vim plugins will not be installed. Of course, installing the packages you selected can also take a while.
The command "apt-get update" doesn't actually install new versions of software. Instead, it updates the package lists for upgrades for packages that need upgrading, as well as new packages that have just come to the repositories.
In simple terms, the only thing apt-get update does is update the local description of what packages are available. That does not download those packages, though it just downloads the updated descriptions.
So, if you are trying to reduce the size of your docker image, then add the instruction
"RUN apt-get update && apt-get -y install --no-install-recommends
" instead of "RUN apt-get update && apt-get -y install".
Top comments (0)