【问题标题】:How to read spring boot application properties from a different docker container?如何从不同的 docker 容器中读取 Spring Boot 应用程序属性?
【发布时间】:2022-01-21 07:33:55
【问题描述】:

当应用程序作为 docker 容器运行时,我已经设法从服务器读取了 spring boot 属性文件,现在我想从不同的 docker 容器中读取属性文件,可以吗?

【问题讨论】:

    标签: spring spring-boot docker application.properties


    【解决方案1】:

    没有。容器永远无法从其他容器的文件系统中读取文件。

    在 Spring 属性的特定情况下,they can be set as environment variables,我的经验是,这是在容器中使用它们的最佳方法。注入文件可能有点棘手,尤其是当您进入 Kubernetes 等集群环境时,并且维护一个包含来自多个地方的潜在输入的命令行参数列表也不能很好地工作。

    例如,如果您希望 Spring 在备用 HTTP 端口上运行,您可以在 Dockerfile 中指定它:

    # Set the Spring server.port property
    ENV SERVER_PORT=3000
    
    # Tell Docker about this
    EXPOSE 3000
    

    【讨论】:

      猜你喜欢
      • 2014-01-07
      • 2017-06-17
      • 1970-01-01
      • 2020-01-22
      • 2017-06-26
      • 1970-01-01
      • 2021-03-22
      • 2022-07-13
      • 2021-08-23
      相关资源
      最近更新 更多