Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker multiline CMD or ENTRYPOINT

I have a really long command line for the default process due to a number of arguments. I think the easiest would be to create a script (for eg.run.sh) and then call this script in your ENTRYPOINT or CMD. I'm wondering if there is a way to make your ENTRYPOINT or CMD multiline (the way we write RUN). For eg.

ENTRYPOINT["/path/myprocess",            "arg1",            "arg2" ] 

I was thinking this is a valid syntax since the format is json. However, docker build throws the error

Step 14 : ENTRYPOINT[ Unknown instruction: ENTRYPOINT[ 

Is there a way I can split the ENTRYPOINT to multiple lines?

like image 914
donnie Avatar asked May 11 '16 09:05

donnie


People also ask

Should I use ENTRYPOINT or CMD?

As a general rule of thumb: Opt for ENTRYPOINT instructions when building an executable Docker image using commands that always need to be executed. CMD instructions are best for an additional set of arguments that act as default instructions till there is an explicit command line usage when a Docker container runs.

What is the difference between docker run CMD and ENTRYPOINT?

The ENTRYPOINT instruction looks almost similar to the CMD instruction. However, the main highlighting difference between them is that it will not ignore any of the parameters that you have specified in the Docker run command (CLI parameters).

Can docker have multiple ENTRYPOINT?

The ENTRYPOINT command makes it so that apache2 starts when the container starts. I want to also be able to start mongod when the the container starts with the command service mongod start . According to the documentation however, there must be only one ENTRYPOINT in a Dockerfile.

Can we use multiple CMD in Dockerfile?

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect. If CMD is used to provide default arguments for the ENTRYPOINT instruction, both the CMD and ENTRYPOINT instructions should be specified with the JSON array format.


1 Answers

It was a typo in the dockerfile. I missed a space between ENTRYPOINT and [. Dockerfile supports multiline ENTRYPOINT and CMD by terminating the line with \, same as RUN. So, in my case it can be

ENTRYPOINT [ "/path/myprocess", \              "arg1",            \              "arg2"             \ ] 
like image 149
donnie Avatar answered Sep 17 '22 16:09

donnie