3

I'm developing a Spring Boot application which I'd like to deploy with Docker.

The trouble I'm having is we need to store the properties file on the server, similar to how Tomcat allows you to put the properties file in /lib.

How would I go about getting Spring Boot to use this file when running inside Docker?

2 Answers 2

2

Docker provides a way to do this using Volumes:

In addition to creating a volume using the -v flag you can also mount a directory from your own host into a container.

$ sudo docker run -d -P --name yourapp -v /lib:/lib yourcontainer/name

So in your containerized app, you would just look in /lib (or wherever you find convenient to mount it), and when you book the container, you specify the host directory you want mounted.

Another option I've used is to create a container with just the configuration (use busybox or something small) and then export a directory from within that as a volume that you share in other containers. This does set up a dependency between containers that you have to manage, but it gives you the benefit of being able to version your configuration and not have to have it just sitting on the host file system.

Both of these strategies are discussed at the link above.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Todd. Mounting the directory on the host worked & the app picked up the /config directory correctly. Appreciate the help.
0

You can also override application.properties file directly:

docker run -v custom.properties:/data/application.properties spring-boot-app

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.