在Docker镜像中使用Terraform运行GOLANG。

huangapple go评论69阅读模式
英文:

Run GOLANG in Docker image FROM Terraform

问题

我的理解是,Terraform Docker镜像是基于Go(Golang)基础镜像构建的。我正在尝试使用Terraform镜像作为基础镜像构建自己的镜像,以便在运行Terraform之前运行一些自定义的Go命令。然而,当我尝试运行Go命令时,它找不到。

FROM hashicorp/terraform:1.1.3

WORKDIR /app

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

RUN echo $(ls)

RUN go mod download

错误日志...

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

如何使我的go命令正常工作?

英文:

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?

答案1

得分: 2

你的基础镜像hashicorp/terraform:1.1.3是基于没有安装Go的Alpine Linux构建的。

解决方法是在使用之前安装Go。可以通过在使用go CLI工具的行之前添加RUN apk add go来实现。

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
英文:

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

huangapple
  • 本文由 发表于 2022年1月19日 06:55:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/70763362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定