In my Spring Boot app I want to externalise the properties to run in a Docker container. When first deployed, the properties that are currently in my-server/src/main/resources/application.yml
are loaded and used by the application as expected. All works fine.
However, my problem is that I need these properties to be updatable as needed, so I need access to the application.yml
file once on the Docker container. But at this point, it's not included in the build/docker/
directory before running the buildDocker
task, so won't be copied over or accessible after first deployment.
So, what I have tried is to copy the Yaml file into the docker/
build directory, copy it to an accessible directory (/opt/meanwhileinhell/myapp/conf
), and use the spring.config.location
property to pass a location of the config to the Jar in my Dockerfile:
ENTRYPOINT ["java",
...
"-jar", "/app.jar",
"--spring.config.location=classpath:${configDirectory}"]
Looking at the Command running on the Docker container I can see that this is as expected:
/app.jar --spring.config.location=classpath:/opt/meanwhileinhell/myapp/conf]
However, when I update a property in this file and restart the Docker container, it isn't picking up the changes. File permissions are:
-rw-r--r-- 1 root root 618 Sep 5 13:59 application.yml
The documentation states:
When custom config locations are configured, they are used in addition to the default locations. Custom locations are searched before the default locations.
I can't seem to figure out what I'm doing wrong or misinterpreting, but probably more importantly, is this the correct way to externalise the config for this type of Docker scenario?
See Question&Answers more detail:os