4

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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
diziaq
  • 6,881
  • 16
  • 54
  • 96

1 Answers1

1

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.

anemyte
  • 17,618
  • 1
  • 24
  • 45
  • 1
    Note that the non-JSON-array form works by wrapping its string in `/bin/sh -c`, so the only actual difference between this answer and the original question is explicitly selecting bash as the shell. – David Maze Jun 04 '21 at 11:44
  • Nicely put, @DavidMaze . Do you mind if I add this to the answer? – anemyte Jun 04 '21 at 12:07