Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker run override entrypoint with shell script which accepts arguments

I have entrypoint shell script which accepts arguments -a -b.

I have working docker-compose.yml file where I override tomcat's entrypoint with instruction:

entrypoint: /usr/local/tomcat/entrypoint.sh -a param1 -b param2 

What is docker run alternative?

docker run --entrypoint "/usr/local/tomcat/entrypoint.sh -a param1 -b param2" tomcat:jre8 

does not work

I get:

docker: Error response from daemon:  invalid header field value "oci runtime error: container_linux.go:247:  starting container process caused \"exec: \\\"/usr/local/tomcat/entrypoint.sh -a param1 -b param2\\\":  stat /usr/local/tomcat/entrypoint.sh -a param1 -b param2:  no such file or directory\"\n". 

FYI:

docker run --entrypoint "/usr/local/tomcat/entrypoint.sh" tomcat:jre8 

works from Docker point of view, but obviously script fails

like image 562
Patrik Mihalčin Avatar asked Jan 17 '17 10:01

Patrik Mihalčin


People also ask

Can you override docker ENTRYPOINT?

You can use one or combine both depending on how you want to run your container. One difference is that unlike CMD , you cannot override the ENTRYPOINT command just by adding new command line parameters. To override ENTRYPOINT you need to modify the docker run command following a specific syntax.

How do I pass args to ENTRYPOINT docker?

So if you want to pass the URL argument to ENTRYPOINT, you need to pass the URL alone. The reason is we have the ab command as part of the ENTRYPOINT definition. And the URL you pass in the run command will be appended to the ENTRYPOINT script. In this case, CMD instruction is not required in the Dockerfile.

Does CMD override ENTRYPOINT?

If you use the ENTRYPOINT instruction in the shell form and you provide additional arguments using CLI parameters or even through the CMD commands, the ENTRYPOINT instruction overrides all of these.

Does ENTRYPOINT override CMD in docker?

Unlike CMD commands, ENTRYPOINT commands cannot be ignored or overridden—even when the container runs with command line arguments stated. A Docker ENTRYPOINT instruction can be written in both shell and exec forms: Exec form: ENTRYPOINT [“executable”, “parameter1”, “parameter2”]


1 Answers

It is because of the quotes you're using around your command.

When you run docker run --entrypoint "/usr/local/tomcat/entrypoint.sh -a param1 -b param2" tomcat:jre8 Docker treats whatever is within those quotes as a single script file.

As you can see from the error:

stat /usr/local/tomcat/entrypoint.sh -a param1 -b param2:  no such file or directory\"\n". 

It's trying to perform a stat on the file before running it, so it knows if it exists.

Place the arguments to your entrypoint at the end of your docker command like so:

docker run --entrypoint <entrypoint.sh> <image:tag> <arg1> <arg2> <arg3> 

Your command becomes:

docker run --entrypoint /usr/local/tomcat/entrypoint.sh tomcat:jre8 -a param1 -b param2  

Have a look at the code snippets in the official documentation:

The ENTRYPOINT of an image is similar to a COMMAND because it specifies what executable to run when the container starts

https://docs.docker.com/engine/reference/run/#/entrypoint-default-command-to-execute-at-runtime

like image 166
Adrian Oprea Avatar answered Sep 22 '22 03:09

Adrian Oprea