I have my spring boot application with a yml to configure it inside a docker containter. Something like that:
spring: application:
name: micro-example
config:
uri: ${vcap.services.config-service.credentials.uri:http://xxx.xxx.xx.73:8888}
As you can see, there is an ip hardcoded in my config, that is a bad idea, because the compililation is just for a server. Does a way exist to externalize the ip, or set it from a docker command line or a better idea?
There many different ways to do it:
1) Set environment variable (use export VCAP_SERVICES_CONFIG-SERVICE_CREDENTIALS_URI='http://example.com'
in shell, or ENV
inside Dockerfile
)
2) Pass it as JVM argument (java -Dvcap.services.config-service.credentials.uri=http://example.com -jar app.jar
)
3) Pass it as command line argument (java -jar app.jar --vcap.services.config-service.credentials.uri=http://example.com
)
4) Spring Boot also reads values from config/application.properties
or application.properties
that are located in the same directory as your executable JAR file, so it's possible to provide this file (you could use VOLUME
for that) and override settings from JAR
See also: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
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