How to execute bash expression in Docker ENTRYPOINT?

5.3k Views Asked by At

There's a Docker file for SpringBoot application with this entry point:

# some lines omitted

ENTRYPOINT java -jar app.jar --spring.config.additional-location=$(ls /config/*.properties | tr '\n' ',')

On container start a host directory is mounted to /config/ directory:

docker run  -p 9999:8080  -v C:/path/to/configuration/:/config   my_image_name

And it works as expected, capturing all *.properties from the host directory and applying them to the app.

For readability I would like to use the format with array of strings in ENTRYPOINT like this:

ENTRYPOINT ["java", "-jar", "app.jar", "--spring.config.additional-location=$(ls /config/*.properties | tr '\n' ',')"]

Unfortunately, the expression inside $(...) is not evaluated at the container start and the application throws an exception that clearly shows the problem:

ERROR org.springframework.boot.SpringApplication - Application run failed
             java.lang.IllegalStateException: Unable to load config data from '')'

How do I express the ENTRYPOINT arguments so the bash expression in $() could be evaluated as in the first case?

1

There are 1 best solutions below

2
On BEST ANSWER

To use bash in entrypoint you need to run bash, and not java:

ENTRYPOINT ["/bin/bash", "-c", "java -jar app.jar --spring.config.additional-location=$(ls /config/*.properties | tr '\n' ',')"]

The first element of an entrypoint is a binary or a script (i.e. what) to be executed. The rest (including CMD) goes as arguments to it. bash -c "some string" runs a sequence of commands passed in a string and it possible to use bash expressions in it.