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

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

Run GOLANG in Docker image FROM Terraform

问题

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

  1. FROM hashicorp/terraform:1.1.3
  2. WORKDIR /app
  3. COPY go.mod ./
  4. COPY go.sum ./
  5. COPY someotherterraformfiles.tf ./
  6. RUN echo $(ls)
  7. RUN go mod download

错误日志...

  1. Step 5/6 : RUN echo $(ls)
  2. ---> Running in a4333944d871
  3. go.mod go.sum
  4. Removing intermediate container a4333944d871
  5. ---> 173d8ba93215
  6. Step 6/6 : RUN go mod download
  7. ---> Running in 4943df7818c2
  8. /bin/sh: go: not found
  9. 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.

  1. FROM hashicorp/terraform:1.1.3
  2. WORKDIR /app
  3. COPY go.mod ./
  4. COPY go.sum ./
  5. COPY someotherterraformfiles.tf ./
  6. RUN echo $(ls)
  7. RUN go mod download

Error log...

  1. Step 5/6 : RUN echo $(ls)
  2. ---> Running in a4333944d871
  3. go.mod go.sum
  4. Removing intermediate container a4333944d871
  5. ---> 173d8ba93215
  6. Step 6/6 : RUN go mod download
  7. ---> Running in 4943df7818c2
  8. /bin/sh: go: not found
  9. 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来实现。

  1. FROM hashicorp/terraform:1.1.3
  2. RUN apk add go
  3. WORKDIR /app
  4. COPY go.mod ./
  5. COPY go.sum ./
  6. COPY someotherterraformfiles.tf ./
  7. RUN echo $(ls)
  8. 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.

  1. FROM hashicorp/terraform:1.1.3
  2. RUN apk add go
  3. WORKDIR /app
  4. COPY go.mod ./
  5. COPY go.sum ./
  6. COPY someotherterraformfiles.tf ./
  7. RUN echo $(ls)
  8. 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:

确定