Home > Enterprise >  Docker ENTRYPOINT shell form with parameters
Docker ENTRYPOINT shell form with parameters

Time:01-11

When I have a Docker image with the following line (a Spring Boot microservice):

ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]

I can start the container using e.g.:

docker run --rm my_image:1.0.0 --spring.profiles.active=local

and it works, the parameter --spring.profiles.active=local is used. However, when the shell form of ENTRYPOINT is used:

ENTRYPOINT java org.springframework.boot.loader.JarLauncher

this doesn't work any more, the parameters are ignored. I believe the parameters are passed to the /bin/sh -c that is what is used by the shell form.

So how do I pass arguments to the app I want to start when using the shell form?

CodePudding user response:

ENTRYPOINT string_here

...has Docker run:

["sh", "-c", "string_here"]

The problem with this is that when you add more arguments, they're added as new elements on the argument vector, as in:

["sh", "-c", "string_here", "arg1", "arg2", "arg3..."]

which means they're ignored, because string_here, when invoked as a script, doesn't look at what further arguments it's given.

Thus, you can use:

ENTRYPOINT string_here "$0" "$@"

where "$@" in shell expands to "$1" "$2" "$3" ..., and $0 is the first argument following -c (which is typically the name of the script or executable, and used in error messages written by the shell itself).

  • Related