简体   繁体   English

执行 docker 图像入口点,这是一个已编译的 go 应用程序,失败并显示“未找到”

[英]Execing docker image entrypoint, which is a compiled go app, fails with "not found"

I have built a small Go app and done local testing of it on my Linux VM.我已经构建了一个小型 Go 应用程序,并在我的 Linux VM 上对其进行了本地测试。

I'm now trying to build a prototype Docker image for it and test running the image.我现在正在尝试为其构建原型 Docker 图像并测试运行该图像。 The Dockerfile structure is pretty simple. Dockerfile 结构非常简单。 I base it on Alpine, copy the executable to the root directory and my entrypoint is running the executable.我基于 Alpine,将可执行文件复制到根目录,并且我的入口点正在运行可执行文件。

It fails with "not found".它因“未找到”而失败。

Now for more details.现在了解更多详情。

Here is the Dockerfile, with some information elided:这是 Dockerfile,省略了一些信息:

FROM <registry>/<namespace>/alpine-base:3.12.3

COPY target/dist/linux-amd64/<appname> /
EXPOSE 8080

RUN echo hello
RUN ls -ltd .
RUN ls -lt
RUN whoami
#ENTRYPOINT ["./<appname>"]
ENTRYPOINT ./<appname>

This is approximately what I do when I build the image:这大约是我在构建图像时所做的:

chmod 777 target/dist/linux-amd64/<appname>
docker build --no-cache -f Dockerfile -t <registry>/<namespace>/<appname>:dev-latest .

This is the output of that:这是 output :

Sending build context to Docker daemon  14.48MB
Step 1/8 : FROM <registry>/<namespace>/alpine-base:3.12.3
 ---> d7eec24f3d29
Step 2/8 : COPY target/dist/linux-amd64/<appname> /
 ---> e056bbe44bd6
Step 3/8 : EXPOSE 8080
 ---> Running in 921cc1fe8804
Removing intermediate container 921cc1fe8804
 ---> 00b30c5a2770
Step 4/8 : RUN echo hello
 ---> Running in 9fb08d924d3c
hello
Removing intermediate container 9fb08d924d3c
 ---> 6788feafae4b
Step 5/8 : RUN ls -ltd .
 ---> Running in 78e6d4aea09f
drwxr-xr-x    1 root     root          4096 Jan 10 23:02 .
Removing intermediate container 78e6d4aea09f
 ---> 711f3d247efe
Step 6/8 : RUN ls -lt
 ---> Running in 32e703a9d480
total 14200
drwxr-xr-x    5 root     root           340 Jan 10 23:02 dev
drwxr-xr-x    1 root     root          4096 Jan 10 23:02 etc
dr-xr-xr-x  324 root     root             0 Jan 10 23:02 proc
dr-xr-xr-x   13 root     root             0 Jan 10 23:02 sys
-rwxrwxrwx    1 root     root      14480384 Jan 10 22:39 <appname>
drwxr-xr-x    1 root     root          4096 Jan 12  2021 home
drwxr-xr-x    1 root     root          4096 Jan 12  2021 opt
drwxr-xr-x    2 root     root          4096 Dec 16  2020 bin
drwxr-xr-x    2 root     root          4096 Dec 16  2020 sbin
drwxr-xr-x    1 root     root          4096 Dec 16  2020 lib
drwxr-xr-x    5 root     root          4096 Dec 16  2020 media
drwxr-xr-x    2 root     root          4096 Dec 16  2020 mnt
drwx------    2 root     root          4096 Dec 16  2020 root
drwxr-xr-x    2 root     root          4096 Dec 16  2020 run
drwxr-xr-x    2 root     root          4096 Dec 16  2020 srv
drwxrwxrwt    2 root     root          4096 Dec 16  2020 tmp
drwxr-xr-x    1 root     root          4096 Dec 16  2020 usr
drwxr-xr-x    1 root     root          4096 Dec 16  2020 var
Removing intermediate container 32e703a9d480
 ---> 68871e80b517
Step 7/8 : RUN whoami
 ---> Running in 40b2460bc349
kube
Removing intermediate container 40b2460bc349
 ---> 4cf57c0b5f10
Step 8/8 : ENTRYPOINT ./<appname>
 ---> Running in 3c57717800ab
Removing intermediate container 3c57717800ab
 ---> eaafc953da46
Successfully built eaafc953da46
Successfully tagged <registry>/<namespace>/<appname>:dev-latest

And this is what I run to test it:这就是我运行的测试:

docker rm <appname>-1
docker run -P --name=<appname>-1 -d -t <registry>/<namespace>/<appname>:dev-latest
docker logs <appname>-1

And this is the output:这是 output:

docker rm <appname>-1
<appname>-1
docker run -P --name=<appname>-1 -d -t <registry>/<namespace>/<appname>:dev-latest
66bb4756783b3ef64d9a4b0d8b7227184ba3b5a3fde25ea0d19b9523285d76b7
docker logs <appname>-1
/bin/sh: ./<appname>: not found

It says "not found".它说“未找到”。 I don't understand that.我不明白。 I showed the contents of the root directory.我显示了根目录的内容。 The file is clearly there.文件显然在那里。 Is this error saying that some OTHER file is not found, like if it thought it was a shell script and the shebang pointed to a shell that doesn't exist?此错误是否表示未找到某些其他文件,例如它认为它是 shell 脚本并且 shebang 指向不存在的 shell?

Update :更新

So the one tiny little detail that I realized I didn't mention in the original post is that disabling CGO is not going to be possible.所以我意识到我在原始帖子中没有提到的一个小细节是禁用 CGO 是不可能的。 The entire reason for this app is to link with a C library and call functions in it, so I have to use Cgo.这个应用程序的全部原因是与 C 库链接并调用其中的函数,所以我必须使用 Cgo。

What I conclude from these helpful comments and other threads like Go-compiled binary won't run in an alpine docker container on Ubuntu host , is that my "workaround" of changing to an ubuntu base image is actually the only reasonable solution.我从这些有用的评论和其他线程(如Go-compiled binary)中得出的结论不会在 Ubuntu 主机上的高山 docker 容器中运行,是我更改为 Z1D41C853AF528D3A7DAE549 基础映像的“解决方法”实际上是唯一合理的解决方案。

It cannot find runtime libraries.它找不到运行时库。 Check if the app is dynamically linked: ldd <app> .检查应用程序是否动态链接: ldd <app>

Rebuild it with static linking: CGO_ENABLED=0 go build使用 static 链接重建它: CGO_ENABLED=0 go build

Change ENTRYPOINT./<appname> to ENTRYPOINT ["/<appname>"] ENTRYPOINT./<appname>更改为ENTRYPOINT ["/<appname>"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM