Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create docker entrypoint with parameters

Tags:

docker

I met a really headache for this issue and almost pull my hair up and still can not resolve it. I want docker image to start automatically whenever I start it, so I came to using entrypoint, but always failed.

This is command I usually use to start my app:

cd /opt/path ./start.sh -l dev -ssl false -srv api

I now want to run this command automatically when docker get started.

I used this in docker file:

WORKDIR /opt/ngcsc
ENTRYPOINT ["start.sh","-l","kubstaging","-ssl", "false", "-srv", "api"] 

I got this error:

docker: Error response from daemon: oci runtime error: exec: "start.sh": executable file not found in $PATH.

But if I change to absolute path:

ENTRYPOINT ["/opt/ngcsc/start.sh","-l","kubstaging","-ssl", "false", "-srv", "api"] 

after I run docker run image

I got:

standard_init_linux.go:175: exec user process caused "exec format error"

This is really a big problem and I googled a lot, nothing worked. can you help to tell me what to do?

Thanks

like image 246
user3006967 Avatar asked Oct 12 '16 23:10

user3006967


1 Answers

Unix is looking for an executable binary to exec, not a shell script. To run the shell script, call it with the appropriate shell, e.g.:

ENTRYPOINT ["/bin/sh", "-c", "/opt/ngcsc/start.sh","-l","kubstaging","-ssl", "false", "-srv", "api"]

Note that this won't make docker automatically start your container when the host reboots. For that, you want the --restart flag on docker run, e.g.:

docker run --restart=unless-stopped -itd your_image
like image 164
BMitch Avatar answered Sep 23 '22 15:09

BMitch