Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to properly pass spring boot jvmArguments to docker?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading