简体   繁体   English

如何从不同的 docker 容器中读取 spring 启动应用程序属性?

[英]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?当应用程序作为 docker 容器运行时,我已经设法从服务器读取 spring 引导属性文件,现在我想从不同的 Z05B6053C41A2130AFD6FC3B158BDA4E6 容器中读取属性文件,可以吗?

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.在 Spring 属性的特殊情况下, 它们可以设置为环境变量,我的经验是这是在容器中使用它们的最佳方法。 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.注入文件可能有点棘手,尤其是当您进入像 Kubernetes 这样的集群环境时,并且维护一个命令行 arguments 列表以及来自多个地方的潜在输入也不能很好地工作。

For example, if you wanted Spring to run on an alternate HTTP port, you could potentially specify this in a Dockerfile:例如,如果您希望 Spring 在备用 HTTP 端口上运行,您可以在 Dockerfile 中指定它:

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

# Tell Docker about this
EXPOSE 3000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot从应用程序属性读取值 - Spring Boot read values from application properties 如何阅读Spring Boot application.properties? - How to read Spring Boot application.properties? Spring Boot 无法读取 Docker 中的 application.properties - Spring Boot can't read application.properties in Docker 将 YAML 属性列表从 Docker compose 传递到 Spring Boot application - Passing list of YAML properties from Docker compose to Spring Boot application 如何使用Tomcat托管的Spring Boot应用程序从Docker Container通过JDBC访问Oracle AWS RDS - How to access Oracle AWS RDS through JDBC from Docker Container with Spring boot application hosted on Tomcat 春季启动:从“ application.properties”读取文件路径 - Spring boot: Read a file PATH from “application.properties” Spring Boot 应用程序在 main 方法中从属性文件中读取值 - Spring Boot application to read a value from properties file in main method 无法从 JUnit 中的 Spring Boot 读取应用程序属性? - Not able to read application properties from Spring Boot in JUnit? 无法从 Spring Boot 应用程序中的 yaml 读取复杂的属性 - Couldn't read complex properties from yaml in Spring boot application 在docker容器中重新部署spring-boot应用程序? - Redeploy spring-boot application in docker container?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM