I have a Dockerfile
like:
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
looks like:
#!/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
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.
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.
I think the trouble here is when you specify path like
/app.jar
, it is really difficult to make out where thecurrent working directory
actually is.It can be any where and I suspect Docker must have accidentally copy your
start.sh
to a place whatever at that point./
is.You might want to ssh into the container and do a
find
to search and see wherestartup.sh
is sitting.docker ps -a
- Find docker container IDdocker -i -t [CONTAINER_ID] /bin/bash
- SSH insidefind . -name "startup.sh"
- Look for file.If you intend to copy the files through using
./
(current working directory), I think it would be better to specify wherecurrent
is. And you can do this using theWORKDIR
keyword.Example:
WORKDIR /path/to/workdir
That way docker will not get confused.
See: https://docs.docker.com/engine/reference/builder/#/workdir
A container exits when its main process exits. So check that
/startup.sh
is not ending.Particularly check that this java
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 tostartup.sh
when copied into the image, which is weird. That prevents the script from being invoked.The solution is to add
dos2unix filename
before the ENTRYPOINT in Dockerfile. But make sure that your base image has that utility.Are you sure though? (I mean within the container, onced ADDed)
To be sure, I would use the Dockerfile: