[英]Unable to start node app with shell script
I created an node.js Docker image. 我创建了一个node.js Docker映像。 Using
CMD node myapp.js
in the end of my Dockerfile
, it starts. 在我的
Dockerfile
末尾使用CMD node myapp.js
,它将启动。 But when I use CMD /root/start.sh
, then it fails. 但是,当我使用
CMD /root/start.sh
,它将失败。
This is how my start.sh
looks like: 这就是我的
start.sh
样子:
#!/bin/bash
node myapp.js
And here are the important lines of my Dockerfile
: 这是我的
Dockerfile
的重要Dockerfile
:
FROM debian:latest
COPY config/start.sh /root/start.sh
RUN chmod +x /root/start.sh
WORKDIR /my/app/directory
RUN apt-get install -y wget && \
wget https://nodejs.org/dist/latest-v5.x/node-v5.12.0-linux-x64.tar.gz && \
tar -C /usr/local --strip-components 1 -xzf node-v5.12.0-linux-x64.tar.gz && \
rm -f node-v5.12.0-linux-x64.tar.gz && \
ln -s /usr/bin/nodejs /usr/bin/node
# works:
CMD node myapp.js
# doesn't work:
CMD /root/start.sh
Using docker logs
I get: standard_init_linux.go:175: exec user process caused "no such file or directory"
But I don't understand, because if I add RUN ls /root
in my Dockerfile, I can see the file exists. 使用
docker logs
我得到: standard_init_linux.go:175: exec user process caused "no such file or directory"
但我不明白,因为如果在Dockerfile中添加RUN ls /root
,我可以看到该文件存在。 I also tried with full paths in my script: 我还在脚本中尝试了完整路径:
#!/bin/bash
/usr/bin/node /my/app/directory/myapp.js
but nothing changed. 但什么都没有改变。 So what can be the problem?
那么可能是什么问题呢?
Most common error I've seen is creating the start.sh on a Windows system and saving the file either with a different character encoding or including windows linefeeds. 我看到的最常见的错误是在Windows系统上创建start.sh并使用不同的字符编码或包含Windows换行符的方式保存文件。 The
/bin/bash^M
is not the same as /bin/bash
but you won't see that linefeed on Windows. /bin/bash^M
与/bin/bash
但是在Windows上看不到该换行符。 You also want to save the file in ascii encoding, not any of the multi-character UTF encodings. 您还希望将文件保存为ascii编码,而不是任何多字符UTF编码。
Use docker run -entrypoint="/bin/bash" -i your_image
. 使用
docker run -entrypoint="/bin/bash" -i your_image
。
What you used is the shell form of dockerfile CMD . 您使用的是dockerfile CMD的外壳形式 。 As described in the doc, the default shell binary is
/bin/sh
, not as your expected /bin/bash
in start.sh
line 1. 如文档中所述,默认的shell二进制文件是
/bin/sh
,而不是您在start.sh
第1行中期望的/bin/bash
。
Or try using exec form , that is CMD ["/root/start.sh"]
. 或者尝试使用exec形式 ,即
CMD ["/root/start.sh"]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.