Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does alpine `apk` have an ubuntu `apt` `--no-install-recommends` equivalent

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?

like image 352
Zak Avatar asked May 08 '17 05:05

Zak


People also ask

Is Alpine same as Ubuntu?

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.

What is apk on Alpine Linux?

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.

How install apk on Alpine Linux?

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.

What is -- no install recommends?

–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]


1 Answers

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?

like image 51
scipilot Avatar answered Sep 17 '22 14:09

scipilot