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
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.
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.
Simply add an application-[profile]. properties file and specify the profiles to use using the spring. profiles. active property.
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
--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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With