简体   繁体   中英

Unable to start node app with shell script

I created an node.js Docker image. Using CMD node myapp.js in the end of my Dockerfile , it starts. But when I use CMD /root/start.sh , then it fails.

This is how my start.sh looks like:

#!/bin/bash
node myapp.js

And here are the important lines of my 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. 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. The /bin/bash^M is not the same as /bin/bash but you won't see that linefeed on Windows. You also want to save the file in ascii encoding, not any of the multi-character UTF encodings.

Use docker run -entrypoint="/bin/bash" -i your_image .

What you used is the shell form of 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.

Or try using exec form , that is CMD ["/root/start.sh"] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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