1
votes

I am trying build docker image for my spring boot docker using the command

mvn spring-boot:build-image

And below is my docker-compose.yml

version: '3.3'
services:
    spring-boot-container:
        ports:
            - '7000:7000'
        environment:
            - SPRING_PROFILES_ACTIVE=${environment}
            - JASYPT_ENCRYPTOR_PASSWORD=${JASYPT_ENCRYPTOR_PASSWORD}
            - cloud_config_uri=${cloud_config_uri}
            - "JAVA_OPTS=-Dspring.cloud.config.uri=http://localhost:8888"   
        image: 'artifactory.cloud.health.com/docker-all/spring_boot_app:latest'
        restart: always
        container_name: spring_boot_app

But my spring boot app is not coming up with proper profiles and not picking java _opts.

Basically in old approach i create dockerfile, then i give ENTRYPOINT where i pass -Dspring.active.profiles.

But since we using mvn spring-boot:build-image i dont know how we pass those entrypoint variables.

1
Why not simply pass SPRING_PROFILES_ACTIVE=dev? Why this complex resolution? Also unless you do something with JAVA_OPTS it won't do a thing. Also shouldn't the " be removed?M. Deinum
where and how do we pass it in compose file, and its not just about spring profiles, i have many arg parameter to pass.VIJ
You currently have 2 competing properties for the profiles only one will remain. I suspect the one from the command line nor will it use JAVA_OPTS if that isn't present in the first place. Also what is that ${environment} if that can't be resolved it will error out.M. Deinum
For profiles yeah i agree, but none of it is working. i just gave to show that i tried in both the places. ${environment} is env i am passign using export command.VIJ
Well ofcourse that won't work. The ${environment} will be resolved inside the docker container not on your local system.M. Deinum

1 Answers

0
votes

Ok, finally resolved, its syntax issue. The below way of writing environment works!

        environment:
            - JAVA_OPTS=
                -Dspring.profiles.active=${environment}
                -Dspring.cloud.config.enabled=true
                -Dspring.cloud.config.uri=${cloud_config_uri}
                -Djasypt.encryptor.password=${JASYPT_ENCRYPTOR_PASSWORD}