Home > Blockchain >  Run GOLANG in Docker image FROM Terraform
Run GOLANG in Docker image FROM Terraform

Time:01-19

My understanding is that the Terraform Docker image is from a Go (Golang) base image. I'm trying to build my own image using the Terraform image as a base, so I can run some custom Go commands before running my Terraform. However when I try to run Go it is not found.

FROM hashicorp/terraform:1.1.3

WORKDIR /app

COPY go.mod ./
COPY go.sum ./
COPY someotherterraformfiles.tf ./

RUN echo $(ls)

RUN go mod download

Error log...

Step 5/6 : RUN echo $(ls)
 ---> Running in a4333944d871
go.mod go.sum
Removing intermediate container a4333944d871
 ---> 173d8ba93215
Step 6/6 : RUN go mod download
 ---> Running in 4943df7818c2
/bin/sh: go: not found
The command '/bin/sh -c go mod download' returned a non-zero code: 127

How do I get my go commands to work?

CodePudding user response:

Your base image, hashicorp/terraform:1.1.3 is built on Alpine Linux, without Go installed.

The solution is to install Go before using it. This can be accomplished with adding RUN apk add go to a line above where the go CLI tool is used.

FROM hashicorp/terraform:1.1.3

RUN apk add go

WORKDIR /app

COPY go.mod ./
COPY go.sum ./
COPY someotherterraformfiles.tf ./

RUN echo $(ls)

RUN go mod download
  •  Tags:  
  • Related