简体   繁体   中英

How to read spring boot application properties from a different docker container?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM