英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论