英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论