I have a spring boot application, which picks up a series of properties from a file, and which path is set as an environment variable. So when I start the spring boot application, I pass the following variable:
--other.properties.path=external/directories/path/otherpropertiesfile.properties
The reason why we use a separate properties file, other than the application properties, is because the spring boot application relies on an underlying (different) application, with a separate properties file parser.
Now that we have moved the spring boot application to a docker image, we would like to pass this path in the environment variables of the docker container. What is currently working, is setting the path at the creation of the container, and then copying the necessary files into the container. After restarting the container, the property file is found and the application runs properly.
I am wondering if there is a better solution, making the external properties file (which is thus not the application.properties) file, available to the docker container, and reading the properties files at startup.
Note: it doesn’t make sense to pack the external properties file at the creation of the image. The properties file needs to be changed easily and regularly, and the different properties included in it are each time different (e.g. containing an encryption key). The best that we could do is copy a template.
Thx a lot!
2
Answers
Thanks to egeorge I got it working.
How I implemented it was the following:
This is a common thing when you start working heavily with SpringBoot
Here is an example of how I would do it.
./src/main/java/com/example/dockerconfig/DockerConfigApplication.java
./src/main/resources/application.properties
./default.properties
./Dockerfile
Build image
Run Image with default config
Override with new file
./extern.properties
To override with this file, we have to mount the file into the container and also override the config property.
-v "$(pwd)"/extern.properties:/extern.properties
makes the file available in the container.-e other.properties.path=extern.properties
overrides the config value.