I am learning how to use Docker with a Spring Boot app. I have run into a small snag and I hope someone can see the issue. My application relies heavily on @Value that are set in environment specific properties files. In my /src/main/resources I have three properties files
- application.properties
- application-local.properties
- application-prod.properties
I normally start my app with: java -jar -Dspring.profiles.active=local build/libs/finance-0.0.1-SNAPSHOT.jar
and that reads the "application-local.properties" and runs properly. However, I am using this src/main/docker/DockerFile:
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD finance-0.0.1-SNAPSHOT.jar finance.jar
RUN sh -c 'touch /finance.jar'
EXPOSE 8081
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /finance.jar" ]
And then I start it as:
docker run -p 8081:80 username/reponame/finance -Dspring.profiles.active=local
I get errors that my @Values are not found: Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.driverClassName' in value "${spring.datasource.driverClassName}"
However, that value does exist in both *.local & *.prop properties files.
spring.datasource.driverClassName=org.postgresql.Driver
Do I need to do anything special for that to be picked up?
UPDATE:
Based upon feedback from M. Deinum I changing my startup to be:
docker run -p 8081:80 username/reponame/finance -eSPRING_PROFILES_ACTIVE=local
but that didn't work UNTIL I realized order matter, so now running:
docker run -e"SPRING_PROFILES_ACTIVE=test" -p 8081:80 username/reponame/finance
works just fine.
ENV SPRING_PROFILES_ACTIVE=local
to your Docker file – Pär Nilsson-Dspring.profiles.active
will obviously do very little for docker. Instead use-e
which is for passing environment variables. Use-e SPRING_PROFILES_ACTIVE=local
instead. – M. Deinum-Dspring.config.location=/app/conf/
into the launch string the problem was solved. The launch string became this:CMD java -Dspring.config.location=/app/conf/ -jar lib/application.jar
– kolyaiks