【问题标题】:How dockerize Spring Boot app if Postgres db is going to be AWS RDS?如果 Postgres db 将成为 AWS RDS,如何 dockerize Spring Boot 应用程序?
【发布时间】:2022-10-21 21:14:50
【问题描述】:
    version: "3.7"
services:
  api_service:
    build: .
    restart: always
    ports:
      - 8080:8080
    depends_on:
      - postgres_db
    links:
      - postgres_db:database
  postgres_db:
    image: "postgres:11.4"
    restart: always
    ports:
      - 5435:5432
    environment:
      POSTGRES_DB: testDb
      POSTGRES_PASSWORD: admin

这是我的 yaml

我得到了属性

spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://database:5432/testDb
spring.datasource.username=postgres
spring.datasource.password=admin

如果我的 postgres 是 rds,那么我是否需要编写它们,或者我只能使用 dockerfile 用于 jar 而不是 yaml 文件?

【问题讨论】:

    标签: spring-boot docker docker-compose


    【解决方案1】:

    您可以为 RDS 地址、RDS 用户名、RDS 密码和 RDS 端口创建环境变量。将其传递给 Dockerfile 到 api_service。您的 api_service 应该知道根据环境变量组装 Postgres 连接字符串。请检查-Spring Profiles in connection String

    【讨论】:

      猜你喜欢
      • 2018-01-10
      • 1970-01-01
      • 2021-07-03
      • 2019-10-05
      • 1970-01-01
      • 2019-11-27
      • 2018-05-29
      • 2019-11-06
      • 2020-04-13
      相关资源
      最近更新 更多