Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass the spring.cloud.config.uri along with the docker run command?

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.

like image 494
Ananya Antony Avatar asked Apr 10 '18 10:04

Ananya Antony


1 Answers

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>
like image 147
M. Deinum Avatar answered Oct 18 '22 07:10

M. Deinum