Paolo Soto
Paolo Soto

Reputation: 83

External properties file using Spring Boot and Docker

i cannot configure a Dockerfile for use external properties file with Spring Boot. This is my Dockerfile:

FROM java:8-jre 
VOLUME /tmp /var/gpm/config
ADD gpm-web-1.0.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-cp","/var/gpm/config","-Dspring.config.location=classpath:application.properties","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

And in my host i have this path to properties file : /var/gpm/config/application.properties

But, don't works.

UPDATE

i change Dockerfile by this:

FROM java:8-jre
VOLUME /tmp
ADD gpm-web-1.0.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar","--spring.config.location=file:/conf/application.properties"]

And run with this:

docker run -d -p 8080:8080 -v /opt/gpm/config/application.properties:/conf/application.properties --name gpm gpm-web:1.0

But, the file is take it like a folder:

root@b7349202b6d3:/# ls -la /conf/
total 8
drwxr-xr-x  3 root root  4096 May 18 16:43 .
drwxr-xr-x 74 root root  4096 May 18 16:55 ..
drwxr-sr-x  2 root staff   40 May 18 16:43 application.properties 

Upvotes: 6

Views: 14185

Answers (2)

user3218881
user3218881

Reputation: 124

I think you only need to mount the volume to the conf folder e.g.

docker run -d -p 8080:8080 -v /opt/gpm/config:/conf --name gpm gpm-web:1.0

Upvotes: 1

Paolo Soto
Paolo Soto

Reputation: 83

Finally, the problem is about permissions of the file to be mounted in Docker container. Docker creates a directory if the original file is not found in host.

Thanks to @Shibashis for the help.

Upvotes: 0

Related Questions