Docker没有这个文件或目录。

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

Docker no such file or directory

问题

我正在尝试为一个 Golang 应用程序编写一个非常简单和直接的 Dockerfile。但是由于某种原因,在尝试运行镜像时出现了以下错误:

exec /app/serverTest: 没有那个文件或目录

我无法弄清楚问题出在哪里,搜索了类似的问题,但没有解决这个问题的运气。

这是我的 Dockerfile:

  1. ## Build
  2. FROM golang:1.20 AS build
  3. WORKDIR /tmp/build
  4. COPY go.mod .
  5. COPY go.sum .
  6. RUN go mod download
  7. COPY . .
  8. RUN go build -o ./out/serverTest .
  9. ## Deploy
  10. FROM golang:alpine
  11. COPY --from=build /tmp/build/out/serverTest /app/serverTest
  12. EXPOSE 8080
  13. 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:

  1. ## Build
  2. FROM golang:1.20 AS build
  3. WORKDIR /tmp/build
  4. COPY go.mod .
  5. COPY go.sum .
  6. RUN go mod download
  7. COPY . .
  8. RUN go build -o ./out/serverTest .
  9. ## Deploy
  10. FROM golang:alpine
  11. COPY --from=build /tmp/build/out/serverTest /app/serverTest
  12. EXPOSE 8080
  13. 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

尝试使用以下命令进行构建:

  1. CGO_ENABLED=0 go build -o ./out/serverTest .
英文:

Try to build with:

  1. CGO_ENABLED=0 go build -o ./out/serverTest .

huangapple
  • 本文由 发表于 2023年3月10日 09:08:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75691416.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定