I was facing the same issue and neither running dos2unix helped, neither was it a CRLF/LF based issue.
What I realized is that I was using a debian based image and to run the script, I had to use
ENTRYPOINT ["sh", "entrypoint.sh"]
So debian image had /bin/sh
and not /bin/bash
. Every shell has its own unique ways of running shell scripts and I learnt an important lesson to not assume that they all run the same.
Also, using an ubuntu:bionic
image is much preferred. It defaults to bash
.
So on the ubuntu:bionic
image, both these work:
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT [“bash”, “entrypoint.sh”]
One way to also verify if your script is being executed correctly, is to have a simple echo "Hello world, this works!"
command in your script and run the image locally.
docker run -it <image> /bin/bash
for ubuntu.
docker run -it <image> /bin/sh
for debian.
If you see and output for the the echo command, things are working fine. Else, it should open up a shell in the root directory of the image.