英文:
Docker no such file or directory
问题
我正在尝试为一个 Golang 应用程序编写一个非常简单和直接的 Dockerfile。但是由于某种原因,在尝试运行镜像时出现了以下错误:
exec /app/serverTest: 没有那个文件或目录
我无法弄清楚问题出在哪里,搜索了类似的问题,但没有解决这个问题的运气。
这是我的 Dockerfile:
## Build
FROM golang:1.20 AS build
WORKDIR /tmp/build
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN go build -o ./out/serverTest .
## Deploy
FROM golang:alpine
COPY --from=build /tmp/build/out/serverTest /app/serverTest
EXPOSE 8080
ENTRYPOINT ["/app/serverTest"]
我尝试过给予 +x 权限,使用 CMD 替代 ENTRYPOINT,更改名称/文件夹等等。
对于问题可能是什么的一些想法吗?
英文:
I'm trying to write a very simple and straightforward docker file for a Golang application. But for some reason it is giving me this error when trying to run the image:
exec /app/serverTest: no such file or directory
I can't figure out what is wrong with it, searched for similar questions but no luck solving the issue.
Here's my dockerfile:
## Build
FROM golang:1.20 AS build
WORKDIR /tmp/build
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN go build -o ./out/serverTest .
## Deploy
FROM golang:alpine
COPY --from=build /tmp/build/out/serverTest /app/serverTest
EXPOSE 8080
ENTRYPOINT ["/app/serverTest"]
I've tried giving +x permissions, using CMD instead of ENTRYPOINT, changing names/folders, among other things..
Some idea on what the problem could be?
答案1
得分: 2
似乎可执行文件在alpine上无法运行。不知道为什么,但如果我将golang:alpine更改为debian:latest,它可以正常工作。
英文:
Seems like the executable file wont run with alpine. Dunno why, but if I change golang:alpine to debian:latest, it works
答案2
得分: 1
尝试使用以下命令进行构建:
CGO_ENABLED=0 go build -o ./out/serverTest .
英文:
Try to build with:
CGO_ENABLED=0 go build -o ./out/serverTest .
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论