Docker组合和Spring Boot Config服务器

我有一个工作的春季启动Web应用程序,从春季启动配置服务器获取其配置属性。 我的应用程序有3个环境 – dev,qa和prod。 在我的资源文件夹中,我有3个文件,bootstarp-qa.properties和。 示例引导文件如下所示 spring.output.ansi.enabled=ALWAYS 

我需要将什么内容放在我的docker-compose文件中,该文件可以从spring启动配置服务器读取配置,并支持3种不同的环境。 有没有人有样品?


我想诀窍是在app.yml文件中,您可以在其中设置要为您的应用程序运行环境的配置文件。 喜欢这个:




 FROM openjdk:8-jre-alpine ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \ DELAY_SLEEP=0 \ JAVA_OPTS="" # add directly the war ADD *.war /app.war EXPOSE 8080 CMD echo "The application will start in ${DELAY_SLEEP}s..." && \ sleep ${DELAY_SLEEP} && \ java ${JAVA_OPTS} -jar /app.war 


 version: '2' services: my-app: image: myapp environment: - SPRING_PROFILES_ACTIVE=prod,swagger - SPRING_DATASOURCE_URL=jdbc:mysql://my-app-mysql:3306/my-app?useUnicode=true&characterEncoding=utf8&useSSL=false - DELAY_SLEEP=10 # gives time for the database to boot before the application ports: - 8080:8080 my-app-mysql: extends: file: mysql.yml service: my-app-mysql 

mysql.yml (如果需要的话)

 version: '2' services: my-app-mysql: image: mysql:5.7.18 # volumes: # - ~/volumes/my-app/mysql/:/var/lib/mysql/ environment: - MYSQL_USER=root - MYSQL_ALLOW_EMPTY_PASSWORD=yes - MYSQL_DATABASE=my-app ports: - 3306:3306 command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8 --explicit_defaults_for_timestamp 


 spring: application: name: my-app profiles: # The commented value for `active` can be replaced with valid Spring profiles to load. # Otherwise, it will be filled in by maven when building the WAR file # Either way, it can be overridden by `` value passed in the commandline or `` set in `JAVA_OPTS` active: cloud: config: fail-fast: false # if not in "prod" profile, do not force to use Spring Cloud Config uri: http://admin:admin@localhost:8761/config # name of the config server's property source (file.yml) that we want to use name: MyApp profile: dev # profile(s) of the property source label: master # toggle to switch to a different version of the configuration as stored in git # it can be set to any label, branch or commit of the config source git repository 
Interesting Posts