Docker图像入口点脚本未找到 [英] Docker Image Entry Point Script Not Found

查看:262
本文介绍了Docker图像入口点脚本未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Dockerfile ,如:

FROM frolvlad/alpine-oraclejdk8:slim
ADD build/libs/zuul*.jar /app.jar
ADD src/main/script/startup.sh /startup.sh
EXPOSE 8080 8999
ENTRYPOINT ["/startup.sh"]

startup.sh 看起来像:

#!/bin/sh
set -e

if [ $# -eq 0 ]
then
    echo "Environment value required"
    exit 1
fi

java -jar -Xms400m -Xmx400m -Dlog4j.configurationFile=log4j2-qa2.xml -Djava.security.egd=file:/dev/./urandom -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.rmi.port=8999 app.jar

但是当我使用 docker run 运行它时,我得到了 docker:守护进程的错误响应:容器命令'/startup.sh '没有找到或不存在.. 。 shell脚本有执行权限。

But when I run it with docker run, I got docker: Error response from daemon: Container command '/startup.sh' not found or does not exist... The shell script has execute permission.

我用同样的方式运行我的其他应用程序,它们都可以正常工作。我在Mac中写了这些文件,并尝试在Linux机器上运行该容器。

I used the same way to run my other apps and they're all working fine. I wrote the files in Mac and tried to run the container in a Linux machine.

推荐答案

原来是 ^ M 导致问题的DOS样式行结束字符。但是,由于我在Mac中编辑,我用vim检查过几次,我很确定本地机器中的起始脚本没有这个字符。但是当在容器内部使用vim打开时,我可以看到 ^ M 到处。所以在某种程度上,当被复制到图像中时,char被添加到 startup.sh 中,这很奇怪。这样可以防止脚本被调用。

It turns out to be the ^M DOS-style line ending character that caused the issue. But since I'm editing in Mac and I checked several times with vim, I'm pretty sure the starting script in my local machine doesn't have that char. But when opened with vim inside the container, I can see ^M everywhere. So somehow that char gets added to startup.sh when copied into the image, which is weird. That prevents the script from being invoked.

解决方案是在Dockerfile中的ENTRYPOINT之前添加 dos2unix filename 。但请确保您的基本图像具有该实用程序。

The solution is to add dos2unix filename before the ENTRYPOINT in Dockerfile. But make sure that your base image has that utility.

这篇关于Docker图像入口点脚本未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆