James Cologne
James Cologne

Reputation: 11

How do I pass external application properties to springboot app in a docker container

Please I have read posts that seem to address this, but I am still not able to solve my problem. I have a default application.properties in my spring boot app running inside a docker container, However I want to add external application.properties.

This is my docker file:

FROM tomcat:8-alpine
COPY target/demoapp.war /usr/local/tomcat/webapps/demo.war
RUN sh -c 'touch /usr/local/tomcat/webapps/demo.war'
EXPOSE 8080
ENTRYPOINT [ "sh", "-c", "java -Djava.security.egd=file:/dev/./urandom -jar /usr/local/tomcat/webapps/demo.war", "--spring.config.location=C:/Users/650/Documents/Workplace/application.properties"]

I build the file with:

docker build . -t imagename

And I run the spring boot docker container with:

docker run -p 8080:8080 -v C:/Users/650/Documents/Workplace/application.properties:/config/application.properties --name demosirs --link postgres-
standalone:postgres -d imagename

The container still doesnt locate my external application.properties, please how do I overcome this challenge ?

Upvotes: 1

Views: 8611

Answers (3)

In your entrypoint pass another argument

-Dspring.config.location=<your custom property file location>

Upvotes: 2

ManojP
ManojP

Reputation: 6248

you can try giving file path instead of the classpath.

 "--spring.config.location=file:${configDirectory}/application.yml"

You can make use of spring cloud config project.

https://spring.io/guides/gs/centralized-configuration/

Upvotes: 1

sujit
sujit

Reputation: 2328

You are referring to the host path in the docker ENTRYPOINT command. Just refer to the container specific path:

ENTRYPOINT [ "sh", "-c", "java -Djava.security.egd=file:/dev/./urandom -jar /usr/local/tomcat/webapps/demo.war", "--spring.config.location=/config/application.properties"]

And, I notice, you are using files as values to the -v argument to docker run. So change that to the corresponding directory:

-v C:/Users/650/Documents/Workplace:/config

Upvotes: 3

Related Questions