donnie
donnie

Reputation: 3439

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?

Upvotes: 109

Views: 58514

Answers (2)

Imre Nagy
Imre Nagy

Reputation: 11

If you have for example:

CMD ["sh", "-c", "docker-entrypoint.sh arg1 arg2 arg3"]

Then it can be written to multiple lines like this:

CMD ["sh", \
     "-c", \
     "docker-entrypoint.sh \
     arg1 \
     arg2 \
     arg3"]

Notice that there is no quotes around args. If you use quotes around them, then the process/script (in my case the docker-entrypoint.sh script) will be executed without args.

Upvotes: 1

donnie
donnie

Reputation: 3439

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"             \
]

Upvotes: 165

Related Questions