These days a netizen asked, how to use Docker to pass spring.profiles.active=test, that is to say springboot switch configuration file. In the past, when we started the jar directly through Java, we directly followed the--spring.profiles.active=test or the JVM parameter-dspring.profiles.active=test to pass. Let me write some orders.
Non-docker springboot switch profile
Java-jar Test.jar--spring.profiles.active=test #第一种情况切换配置文件
Java-dspring.profiles.active=test-jar Test.jar #第二种情况切换配置文件
Some friends will wonder, through the JVM parameters how can switch it, in fact, Springboot is supported OH.
Docker under springboot switch configuration file
Docker encapsulates the springboot after the switch will be more steps, in fact, it is not difficult. I find a lot of articles on the Internet, and did not see through com.spotify:docker-maven-plugin this Docker packaging plug-in implementation of the environment variables passed parameters, it may be too simple, no one to write, but I see a lot of people need, I still write about it. However, there is an env variable passed through Dockerfile implemented on-line. Below I post the package plugin code in the POM:
Note the changes in ENV nodes and entrypoint
Com.spotifydocker-maven-plugin0.4.11pumelo/${project.artifactid}-${version}frolvlad/alpine-oraclejdk8:slim "" [" SH ","-C "," Java $JAVA _opts-jar/${project.build.finalname}.jar "]/${project.build.directory}${ Project.build.finalname}.jar
Test
After the image is newly packaged, run
Docker run-e java_opts= '-xms128m-xmx256m-dspring.profiles.active=prod '-it pumelo/test-1.0.0/bin/bash
This allows you to switch the Springboot configuration file through the JVM parameters.
Thank you for your crossing.
Springboot Docker start parameter delivery