简体   繁体   English

多级 docker 构建并传输已安装的库

[英]Multistage docker build with transfer of installed libraries

I'm using a multi stage docker file.我正在使用多级 docker 文件。 As so:这样:

FROM linuxbrew/brew
WORKDIR home/../
RUN brew update
RUN brew install go-task/tap/go-task
RUN brew install helmfile
RUN brew install k3d
RUN brew install kubectl

FROM docker
COPY --from=0 /usr/local /usr/local
RUN task --version

In the first stage I install a bunch of libraries using homebrew.在第一阶段,我使用自制软件安装了一堆库。 Then in the second stage I then want to transfer the libraries to a 'docker in docker' image.然后在第二阶段,我想将库转移到“docker in docker”图像。 However the installed libraries don't seem to be available in the final docker image:但是,最终 docker 映像中似乎没有安装的库:

The final line task --version fails saying task: not found .最后一行task --version失败说task: not found Why is it not found?为什么找不到?

(I would just use apk in the docker image, but helmfile isn't available from apk. If there is an alternative approach to this problem I would be interested to hear it - thanks!) (我只会在 docker 图像中使用 apk,但 helmfile 不能从 apk 获得。如果有其他方法可以解决这个问题,我很想听听 - 谢谢!)

Actually, for your case (and since you asked if there is an alternative approach to this problem), it would be easier in your case to have a single stage build, and install the binaries directly from the releases.实际上,对于您的情况(并且由于您询问是否有解决此问题的替代方法),在您的情况下,进行单阶段构建并直接从发行版安装二进制文件会更容易。 You would be able to set the versions of your binaries to have reproducible builds.您将能够将二进制文件的版本设置为具有可重现的构建。 The following Dockerfile should work:以下Dockerfile应该可以工作:

FROM    docker

RUN     wget -q -O /usr/local/bin/kubectl https://dl.k8s.io/release/v1.24.0/bin/linux/amd64/kubectl \
 &&     chmod u+x /usr/local/bin/kubectl \
 &&     wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | TAG=v5.4.4 sh \
 &&     wget -q -O /usr/local/bin/helmfile https://github.com/roboll/helmfile/releases/download/v0.144.0/helmfile_linux_amd64 \
 &&     chmod u+x /usr/local/bin/helmfile

Here, I have set the latest versions at the time of writing ( kubectl version 1.24.0, k3d version 5.4.4, helmfile version 0.144.0), but feel free to change them.在这里,我设置了撰写本文时的最新版本( kubectl版本 1.24.0, k3d版本 5.4.4, helmfile版本 0.144.0),但可以随意更改它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM