Home > Software engineering >  How to read spring boot application properties from a different docker container?
How to read spring boot application properties from a different docker container?

Time:12-20

I have managed to read the spring boot property files from the server when the application is running as docker container, now I want to read the property files from a different docker container, can it be done?

CodePudding user response:

No. Containers can never read files from other containers' file systems.

In the particular case of Spring properties, they can be set as environment variables, and my experience has been that this is the best approach for using them in containers. Injecting files can be a little bit tricky, especially as you get into clustered environments like Kubernetes, and maintaining a list of command-line arguments with potential inputs from multiple places doesn't work well either.

For example, if you wanted Spring to run on an alternate HTTP port, you could potentially specify this in a Dockerfile:

# Set the Spring server.port property
ENV SERVER_PORT=3000

# Tell Docker about this
EXPOSE 3000
  • Related