英文:
Building a docker image to run go applications
问题
我正在构建一个在 macOS(Monterrey)上的 Docker 镜像,使用以下 Dockerfile:
FROM golang:latest
WORKDIR /src
COPY go.* ./
RUN go mod download
COPY . /src
RUN go build -o /main
ENTRYPOINT ["/main"]
在第三行之前都正常工作,但在第四行时出现以下错误:
=> ERROR [4/6] RUN go mod download 0.2s
------
> [4/6] RUN go mod download:
#8 0.206 go mod download: no modules specified (see 'go help mod download')
------
executor failed running [/bin/sh -c go mod download]: exit code: 1
请问在下载依赖项时我做错了什么?
英文:
I am building a docker image on mac OS (Monterrey) with below dockerfile
FROM golang:latest
WORKDIR /src
COPY go.* ./
RUN go mod download
COPY . /src
RUN go build -o /main
ENTRYPOINT ["/main"]
It works fine til the 3rd line and on the 4th it complains of
=> ERROR [4/6] RUN go mod download 0.2s
------
> [4/6] RUN go mod download:
#8 0.206 go mod download: no modules specified (see 'go help mod download')
------
executor failed running [/bin/sh -c go mod download]: exit code: 1
Any clues what I am doing wrong while the dependencies are being downloaded?
答案1
得分: 0
我在工作目录中缺少以下列出的几个文件。这些文件是下载依赖项所需的。
Dockerfile //这个文件已经在文件夹中了。
go.sum
go.mod
main.go
英文:
I was missing couple of files from the Working directory as listed below. These are needed to download the dependencies.
Dockerfile //this was already in the folder.
go.sum
go.mod
main.go
答案2
得分: -2
使用download
命令时,需要指定要下载的包,而不是使用go mod tidy && go mod vendor
命令。
英文:
Instead of using download do :
go mod tidy && go mod vendor
You need to specify which package to download when you use "mod download"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论