Home > Back-end >  Super newbie multi-stage docker image build question
Super newbie multi-stage docker image build question

Time:11-21

I need to build custom image which contains both terraform and the gcloud CLI. Very new to docker so I'm struggling with this even though it seems very straight forward. I need to make a multi stage image from the following two images:

google/cloud-sdk:slim
hashicorp/terraform:light

How can I copy the terraform binary from the hashicorp/terraform:light image to the google/cloud-sdk:slim image? Any fumbling I've done so far has given me countless errors. Just hoping somebody could give me an example of what this should look like because this is clearly not it:

FROM hashicorp/terraform:light AS builder

FROM google/cloud-sdk:slim
COPY --from=builder /usr/bin/env/terraform ./

Thanks!

CodePudding user response:

That's not really the purpose of multistaging. For you case, you would want to pick either image and install the other tool, instead of copying from one to another.

Multistage is meant when you want to build an app but you don't want to add building dependencies to the final image in order to reduce the image size and reduce the attach surface.

So, for example, you could have a Go app and you would have two stages:

  • The first stage would build the binary, downloading all the required dependencies.
  • The second stage would copy the binary from the first stage, and that's it.
  • Related