Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set parameters from docker command line to configure spring boot application?

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?

like image 870
Rys Avatar asked Mar 14 '23 18:03

Rys


1 Answers

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

like image 181
Slava Semushin Avatar answered Mar 17 '23 19:03

Slava Semushin