Home > Back-end >  Multistage docker build with transfer of installed libraries
Multistage docker build with transfer of installed libraries

Time:08-15

I'm using a multi stage docker file. 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. However the installed libraries don't seem to be available in the final docker image:

The final line task --version fails saying 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!)

CodePudding user response:

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:

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.

  • Related