我正在尝试从Dockerfile构建Docker映像,该Dockerfile复制并提取.zip
包含可执行文件(myapp
以及其他文件)的档案。有一个docker-entrypoint.sh
运行可执行文件的脚本。在docker build
成功完成,但是当我运行映像入口点脚本失败说,可执行文件无法找到。
$ docker build .
Successfully built 890ec2f09ad4
$ docker run 890ec2f09ad4
./docker-entrypoint.sh: line 3: ./myapp: not found
我已经验证了可执行文件已从存档中提取出来,并且通过执行ls -l
indocker-entrypoint.sh
脚本在正确的目录中运行了该命令。
-rwxrwxr-x 1 root root 45 Jan 20 22:16 docker-entrypoint.sh
-rwxr-xr-x 1 root root 71473 Jan 20 22:16 myapp
-rw-r--r-- 1 root root 177 Jan 20 22:16 myapp.ini
如果我docker-entrypoint.sh
在Docker映像之外的可执行文件旁边运行相同的脚本,则一切运行正常。
我也尝试过:
ubuntu:latest
基本映像(相同错误)我还能尝试什么?我是Docker的新手,这似乎很容易完成,所以我不确定我哪里出错了...
Dockerfile:
FROM alpine:latest
RUN mkdir -p /opt/app/
WORKDIR /opt/app/
COPY target/products/myapp.zip .
RUN unzip myapp.zip && rm myapp.zip
COPY docker-entrypoint.sh .
RUN chmod +x docker-entrypoint.sh
ENTRYPOINT ["./docker-entrypoint.sh"]
docker-entrypoint.sh:
#!/bin/sh
./myapp
感谢@VolArt将我的注意力转向可执行文件类型。
原来,问题在于可执行文件(ELF 64位LSB可执行文件,动态链接)与Alpine之间的兼容性。解决方案是简单地使用其他基础图像。最后,我还需要JRE 8,因此我选择了openjdk:8-jre
基础映像。(我还需要手动安装unzip
)
有助于查明问题的相关文章:
Dockerfile:
FROM openjdk:8-jre
RUN mkdir -p /opt/app/
WORKDIR /opt/app/
RUN apt-get update && apt-get upgrade -y
RUN apt-get install unzip -y
COPY target/products/myapp.zip .
RUN unzip myapp.zip && rm myapp.zip
COPY docker-entrypoint.sh .
RUN chmod +x docker-entrypoint.sh
EXPOSE 8081
ENTRYPOINT ["/opt/app/docker-entrypoint.sh"]
docker-entrypoint.sh:
#!/bin/sh
/opt/app/myapp
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句