Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add external application.properties file to a dockerized spring boot web app inside tomcat

I have a docker image of tomcat with my spring boot web app inside tomcat /webapps folder. The app has its own application.properties file packed in the folder. I want to give the option for anyone running the docker image to mount it's own external application.properties file for the spring boot web app to run by.

How can this by accomplished? thank you very much

like image 491
TommyW Avatar asked May 17 '17 08:05

TommyW


People also ask

How do I import external properties into Spring boot?

Imagine you have an external config file: application-external. yml in the conf/ dir under your home directory, just add it like this: -Dspring. config. location=file:${home}/conf/application-external.

How do I apply different application properties in Spring boot?

Properties files are used to keep 'N' number of properties in a single file to run the application in a different environment. In Spring Boot, properties are kept in the application. properties file under the classpath. Note that in the code shown above the Spring Boot application demoservice starts on the port 9090.

How do I set environment specific properties in Spring boot?

Simply add an application-[profile]. properties file and specify the profiles to use using the spring. profiles. active property.


3 Answers

Similar answer to agnul, you can mount an volume from the docker engine's host, see here

Something like:

docker run -d -P --name web -v /config:/config ...

When you start your JVM you give the system property to /config

java -jar myproject.jar --spring.config.location=file:/config/application.properties
like image 186
Essex Boy Avatar answered Oct 23 '22 23:10

Essex Boy


--spring.config.location=file:/config/application.properties

could be possibly put to JAVA_OPTS environment variable you specify in file where you start the docker image.

like image 2
user1601422 Avatar answered Oct 23 '22 23:10

user1601422


You could try something along the lines of configuring your application class path to reference a path that your docker container will mount as a volume or bind to the host file-system and put your configuration file there.

like image 1
agnul Avatar answered Oct 23 '22 23:10

agnul