0

I have a problem where I'm trying to pass environmental variable in Docker as command line argument for Spring, but not via -Drun.arguments, but as normal command line argument because I need it in class that implements CommandLineRunner and because as I read somewhere CommandLineRunner only takes arguments that are written after your application .jar file in command line, i.e. java -jar app.jar commandlineargument.

In docker file I have this:

ENV SPRING_PROFILE="" \
    JAVA_ARGS0=""

CMD ["java","-jar","-Dspring.profiles.active=${SPRING_PROFILE}","app.jar","--${JAVA_ARGS0}"]

When app starts it successfully reads the variable SPRING_PROFILE and it starts with profile I put in configmap, but when I print my arguments in class that implements CommandLineRunner, value of the argument is string ${JAVA_ARGS0} instead of value from the variable.

I checked if the value is set for JAVA_ARGS0 and it is, so I'm wondering how am I supposed to pass the value.

fenste
  • 21
  • 3
  • Use a plain string, not a JSON array; `CMD java -jar app.jar --${JAVA_ARGS0}`. – David Maze Aug 11 '22 at 10:46
  • In a Spring context, also consider that Spring can read properties from environment variables, so setting `ENV SPRING_PROFILES_ACTIVE=...` might be easier than using a command-line argument. Depending on how the additional arguments are being used, passing them via environment variables might be easier than using positional arguments. – David Maze Aug 11 '22 at 10:48

0 Answers0