docker run执行时出现“/main: 没有该文件或目录”的错误,但文件确实存在。

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

docker run gives exec /main: no such file or directory when the file exists

问题

这是我的Dockerfile:

FROM alpine:latest
COPY ./main .
COPY ./configs/. .
EXPOSE 8081
CMD ["/main"]

如果我运行 docker run -it --entrypoint=/bin/sh metadata,我可以看到 /main 文件存在且可执行。

/ # ls -lart /main
-rwxrwxr-x    1 root     root      15352712 May 29 19:16 /main

这是一个Go二进制文件,因此没有未满足的依赖关系。

但当我尝试运行它时,它说 /main 文件不存在,尽管它在那里:

$ docker run -p 8081:8081 -it metadata
exec /main: no such file or directory

这是Docker的一个bug吗?

我正在Ubuntu 22.04上运行docker 20.10.21。

--编辑--

我尝试在Docker内部运行 /main 二进制文件,但Alpine发行版找不到它来执行:

$ docker run -it --entrypoint=/bin/sh metadata
/ # ls -l /main
-rwxrwxr-x    1 root     root      15352712 May 29 19:16 /main
/ # /main
/bin/sh: /main: not found
/ # ls
base.yaml  dev        home       main       mnt        proc       run        srv        tmp        var
bin        etc        lib        media      opt        root       sbin       sys        usr
/ # ./main
/bin/sh: ./main: not found
/ # main
/bin/sh: main: not found
英文:

Here's my Dockerfile:

FROM alpine:latest
COPY ./main .
COPY ./configs/. .
EXPOSE 8081
CMD ["/main"]

If I do docker run -it --entrypoint=/bin/sh metadata I can see the /main file is there and is executable

/ # ls -lart /main
-rwxrwxr-x    1 root     root      15352712 May 29 19:16 /main

This is a Go binary so there are no unsatisfied dependencies.

When I try to run it it says that the /main file doesn't exist, even though it is there:

$ docker run -p 8081:8081 -it metadata
exec /main: no such file or directory

Is this a bug in docker?

I'm running docker 20.10.21 on Ubuntu 22.04.

--Edit--

I've tried running the /main binary from within docker and the Alpine distro can't find it to exec it:

$ docker run -it --entrypoint=/bin/sh metadata
/ # ls -l /main
-rwxrwxr-x    1 root     root      15352712 May 29 19:16 /main
/ # /main
/bin/sh: /main: not found
/ # ls
base.yaml  dev        home       main       mnt        proc       run        srv        tmp        var
bin        etc        lib        media      opt        root       sbin       sys        usr
/ # ./main
/bin/sh: ./main: not found
/ # main
/bin/sh: main: not found

答案1

得分: -2

我用以下方式解决了这个问题:

FROM ubuntu:22.04

看起来alpine不兼容我的二进制文件。

英文:

I solved this with

FROM ubuntu:22.04

It looks like alpine is not compatible with my binary.

huangapple
  • 本文由 发表于 2023年5月30日 03:50:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76359995.html
匿名

发表评论

匿名网友

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

确定