I have a spring-boot app that I run using:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dlocal=true -DignoredName=GREGORY"
Now I’ve created a docker image using: mvn spring-boot:build-image
However I can’t seem to get it running properly in docker, I thought the correct way to run it was by using the -e but it seemingly doesn’t get picked up.
The command I tried:
docker run -it -p8080:8080 librarybooks:1.0.0-SNAPSHOT -e spring-boot.run.jvmArguments="-Dlocal=true -DignoredName=GREGORY"
>Solution :
The reason why your command isn’t working is because you’re passing the -e option to docker run, which is used to set environment variables, but you’re trying to use it to pass a JVM argument to your Spring Boot application.
To pass JVM arguments to your Spring Boot application when running it in a Docker container, you can use the JAVA_TOOL_OPTIONS environment variable instead. Here’s an example of how you could modify your docker run command to include the JVM arguments:
docker run -it -p 8080:8080 -e "JAVA_TOOL_OPTIONS=-Dlocal=true -DignoredName=GREGORY" librarybooks:1.0.0-SNAPSHOT
In this example, the JAVA_TOOL_OPTIONS environment variable is set to the string "-Dlocal=true -DignoredName=GREGORY", which will be picked up by the JVM when your Spring Boot application starts.