I have a dockerfile that creates an image that starts a Spring Boot application with -Dspring_profiles_active=test on the command line. Now I want to be able to override the profile based on the environment. I had thought that passing an environment variable like -e SPRING_PROFILES_ACTIVE=dev when starting the container would override the command line setting, but it does nothing. If I pass -e spring_profiles_active=dev I get both as shown in the Spring Boot logs: ... : The following profiles are active: dev,test, not what I wanted.
Why doesn't the uppercase version do anything, and
Why does the lowercase version "include" rather than replace?
I thought the precedence order was OS environment variable, then command line (i.e. -D) then application.properites, as per the documentation: Externalized Configuration
EDIT: Corrected typo above. Also, I'm using Spring Boot v1.5.9.RELEASE, Spring v4.3.13.RELEASE and if I remove the -Dspring_profiles_active=test command line options the OS environment variable then passes into the application as expected.
Cheers,
Matt
Use
-e SPRING_PROFILES_ACTIVE=dev
Instead of
-e SPRING_PROFILE_ACTIVE=dev
It is PROFILES
Related
Why docker-compose up command always falling back to default spring boot profile though we have override it in application.properties file . like
SPRING_PROFILES_ACTIVE=schemaDevelopment
The format for setting the active profile in the application.properties file is wrong, example: spring.profiles.active=production
See https://docs.spring.io/spring-boot/docs/2.7.x/reference/html/howto.html#howto.properties-and-configuration.set-active-spring-profiles
The format SPRING_PROFILES_ACTIVE is used when you set the profile via an environmental variable
I have a quarkus based webapp that uses Basic Authentication with Embedded Realm Configuration. The webapp runs in a docker container. The authentication properties are specified in application.properties like this:
quarkus.http.auth.basic=true
quarkus.security.users.embedded.enabled=true
quarkus.security.users.embedded.plain-text=true
quarkus.security.users.embedded.users.test=mypass
quarkus.security.users.embedded.roles.test=admin
I would like to override quarkus.security.users.embedded.users.test to specify a password at docker runtime.
I tried to do this by overriding the quarkus property using an environment variable at docker runtime.
docker run -p 9999:9999 -e QUARKUS_SECURITY_USERS_EMBEDDED_USERS_TEST=newpasswd mywebapp
This does not work. When I access mywebapp using http://locahost:9999 I must login using test/mypass. I expected to login using test/newpasswd.
Any help greatly appreciated.
I suggest you report an issue for this problem. While Quarkus won't be able to "enumerate" any new users from environment variables (the correct property names cannot be deduced), I think it should still be possible to override the password of a user that has already been specified in application.properties using an environment variable like you try to do.
Im Developing a simple docker file for a spring boot war file.
FROM openjdk:8-jdk-alpine
ARG CONFIG_LOC=/app_config
RUN mkdir $CONFIG_LOC
COPY app_config/* $CONFIG_LOC/
ARG JAR_FILE=target/*.war
COPY ${JAR_FILE} app.war
ENTRYPOINT ["java","-Dspring.config.location=/app_config","-Dspring.profiles.active=docker","-jar","/app.war"]
Some how the argument config location is not are not loading when running the spring application. So the spring application is not running.
Is there a reason to use these as arguments? Usually using something like ARG CONFIG_LOC means you're passing a value in your build command using --build-arg. Seems like in this build you should just use hard coded values. When running the application, any argument should be passed as an environment variable using the -e flag.
I want to override certain properties during deployment of my spring boot application.
when I try the following it works
sudo /etc/init.d/myapp start --app.env=prod
I see the app.env is correctly set to prod (my /health just echoes this values)
however when I set more than one property it did not work,
sudo /etc/init.d/myapp start --app.env=prod --version=2.3.4
I see only app.env is correctly set. the version value is not overridden.
why is it so? what is the right way to pass multiple parameters.
NOTE: I want to pass username and password for datasources. but for testing purposes, I kept it simple to override these properties.
You would want to read the section around Customizing the startup script. Specifically that you can include a myapp.conf file beside the jar file. In that .conf file is a JAVA_OPTS variable. You would then use -Dapp.env=prod -Dversion=2.3.4
I'm using Spring 3.1.3 and the new profile feature. When I set the environment in my IDE for spring_profiles_active=NONPROD, it works fine. However, when I deploy to our aPaaS environment which is also using Tomcat, it isn't getting picked up.
Shouldn't I just be able to do the following:
env:
CATALINA_OPTS: -Dspring_profiles_active=NONPROD
If I ssh to the machine, I see this is getting set. Any ideas why Spring isn't picking this up?
Put the following lines to your manifest.yml file to get the Spring profile activated in Stackato:
env:
spring_profiles_active:
default: NONPROD
This will put spring_profiles_active into environment variable and Spring happily reads it from there. Note that you have to use underscores in the variable name, because Stackato doesn't like dots in those. The reason is that Linux environment variable names shouldn't contain dots for shell programs to work correctly with them.