Admin-Ahead Community

General Category => General Discussion => Topic started by: joseletk on June 16, 2018, 10:53:00 am

Title: How to fix docker: exec format error
Post by: joseletk on June 16, 2018, 10:53:00 am
For example, you want to execute the following shell script.

Code: [Select]
# /usr/local/bin/run.sh

echo "hello, world"

Dockerfile

Code: [Select]
ADD run.sh /usr/local/bin/run.sh
RUN chmod +x /usr/local/bin/run.sh
CMD ["/usr/local/bin/run.sh"]

When you run the container, your expectation is the container prints out hello, world. However, what you will get is a error message:

$ docker run -i hello_world_image

You see this message when you didn’t put shebang in your script, and because of that, default entry point /bin/sh -c does not know how to run the script.


To fix this, you can either add shebang

/usr/local/bin/run.sh

Code: [Select]
#!/bin/bash
echo "hello, world"

or you can specify from command line.

Code: [Select]
$ docker run -entrypoint="/bin/bash" -i hello_world_image==========================================================================