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

爱⌒轻易说出口 提交于 2020-08-01 03:08:22

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/43840365/does-alpine-apk-have-an-ubuntu-apt-no-install-recommends-equivalent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!