I'm a beginner to docker and hence the doubt. I have a simple spring boot application fetching properties from a config server. I want to dockerize my application and have a static image that can be used across environments. Assuming the config server url will change in higher environments , is it possible to pass the config server url (spring.cloud.config.uri) along with the docker run command? My docker file has an ENTRYPOINT mentioning java -jar for starting the application.
As explained in the Spring Boot reference guide Spring Boot will read properties from different sources. One of those sources is the environment.
It is also documented that relaxed binding can be used to bind properties. The latter means that spring.profiles.active
and SPRING_PROFILES_ACTIVE
will both work to specify the active profile. This applies to ALL properties that Spring Boot tries to resolve, so it also applies to spring.cloud.config.uri
.
Using Docker you can specify environment variables those will be available in the container as environment variables.
Those 2 things combined make it possible to supply values to Spring Boot through Docker Environment variables.
docker run --env SPRING_CLOUD_CONFIG-URI=<your-environment-url-here> -d -p 8080:8080 <container-id>
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