I'm trying to make the absolute smallest Docker image I can get away with, so I have switched from ubuntu as my base to alpine.
For apt
, I used to use --no-install-recommends
to minimize "dependencies" installed with my desired packages. Is there an equivalent flag I need to pass along with apk
or is this the default behavior for this slimmed down OS?
Alpine linux is a linux distribution primarily made for the deploying application on linux distribution and is a rising competitor for the Ubuntu. Alpine Linux is designed for security, simplicity and resource effectivity. It is designed to run directly from RAM.
apk is the Alpine Package Keeper - the distribution's package manager. It is used to manage the packages (software and otherwise) of the system. It is the primary method for installing additional software, and is available in the apk-tools package.
Get an "online" Alpine machine and download packages. Example is with "zip" and "rsync" packages: Update your system: sudo apk update. Download only this packages: apk fetch zip rsync.
–no-install-recommends : By passing this option, the user lets apt-get know not to consider recommended packages as a dependency to install. apt-get --no-install-recommends [...COMMAND]
No it doesn't have the same flag I think because it does not even do the same behaviour of downloading recommended packages.
However there is another flag --virtual
which helps keep your images smaller:
apk add --virtual somename package1 package2
and then
apk del somename
This is useful for stuff needed for only build but not for execution later.
Note you must execute it in one RUN command, else it cannot be deleted from the previous Docker image layer.
e.g. if pything1
needs package1
and package2
to run, but only needs package3
and package4
during the install build, this would be optimal:
RUN apk add --no-cache package1 package2
RUN apk add --no-cache --virtual builddeps package3 package4 && \
pip install pything1 && \
apk del builddeps
package 3 and 4 are not added the "world" packages but are removed before the layer is written.
This question asks the question other way round: What is .build-deps for apk add --virtual command?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With