我可以在使用golang:1.13base 时运行 Web 应用程序的 docker 映像,但在使用scratch. 工作的 Dockerfile 是:FROM golang:1.13 AS builderWORKDIR /appCOPY . .RUN go build -o serverFROM golang:1.13COPY --from=builder /app/server /app/serverCOPY --from=builder /app/credentials/service-account.json /app/credentials/service-account.jsonENTRYPOINT ["/app/server"]但是当我像这样将最终图像库更改为scratch(第 6 行)时:FROM golang:1.13 AS builderWORKDIR /appCOPY . .RUN go build -o serverFROM scratch # <-- CHANGEDCOPY --from=builder /app/server /app/serverCOPY --from=builder /app/credentials/service-account.json /app/credentials/service-account.jsonENTRYPOINT ["/app/server"]我得到一个standard_init_linux.go:211: exec user process caused "no such file or directory"错误。要构建 docker 映像,我使用docker build -t myimage .,要运行映像,我使用docker run --rm -p 8080:8080 myimage:latest.该应用程序是一个基于 Go 的 Web API,它使用 Gin 框架和 GCP 服务帐户来访问 GCP 服务(我在构建时复制的 JSON 文件。)
1 回答

潇湘沐
TA贡献1816条经验 获得超6个赞
如果您不使用 CGO(如@jakub 所述),请尝试在您的构建中禁用 CGO。
所以改变你的这一行Dockerfile:
#RUN go build -o server
RUN CGO_ENABLED=0 go build -o server
- 1 回答
- 0 关注
- 112 浏览
添加回答
举报
0/150
提交
取消