1

Im building a docker image from maven using io.fabric8:docker-maven-plugin.

i want the container to run like :

java -jar -Dspring.profiles.active=prod /maven/myapp-1.4.3.jar

java -jar -Dspring.profiles.active=dev /maven/myapp-1.4.3.jar

so i actually want the image to pass -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE and that variable will be passed in via docker run when starting a container:

docker run --env SPRING_PROFILES_ACTIVE=prod

however, it looks like the container run this command:

java -jar -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE /maven/myapp-1.4.3.jar

and the $SPRING_PROFILES_ACTIVE is not replaced with the env var.

pom.xml:

            <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.31.0</version>
            <extensions>true</extensions>
            <configuration>
                <verbose>true</verbose>
                <images>
                    <image>
                        <name>${docker.registry}/${project.artifactId}</name>
                        <build>
                            <from>java:8-jdk-alpine</from>
                            <tags>
                                <tag>${project.version}</tag>
                                <tag>latest</tag>
                            </tags>

                            <entryPoint>
                                <exec>
                                    <args>java</args>
                                    <args>-jar</args>
                                    <!--<args>-Dspring.profiles.active=$SPRING_PROFILES_ACTIVE</args>-->
                                    <args>/maven/${project.artifactId}-${project.version}.jar</args>
                                </exec>
                            </entryPoint>
                            <assembly>
                                <descriptorRef>artifact</descriptorRef>
                            </assembly>
                        </build>
                    </image>
                </images>
chenchuk
  • 5,324
  • 4
  • 34
  • 41
  • actually i find a simple solution. passing env var is enough, no need to explicitly type -Dspring.profiles.active (spring knows from the environment var). however the question is still interesting for the general case of variable substitution which is not 'out of the box' as spring.profiles.active . – chenchuk Nov 04 '19 at 22:58
  • you are mixing approaches (or set env (x)or -Dproperty...) ...http://www.littlebigextra.com/use-spring-profiles-docker-containers/ – xerx593 Nov 04 '19 at 23:00

0 Answers0