docker撰写后PostgreSQL连接失败

时间:2020-09-16 12:55:01

标签: postgresql docker jhipster

我正在使用JHipster,当我使用docker启动应用程序时-撰写该应用程序无法连接至数据库。启动时是否需要创建数据库用户?

{
    "WORK_REQUEST_KEY": 2,
    "PROJECT_NAME": "This has now been updated",
    "WR_TYPE_KEY": 2
}
{
    "WORK_REQUEST_KEY": 2,
    "PROJECT_NAME": "This has now been updated",
    "WR_TYPE_KEY": 2
}

app.yml

gestao-app_1         | org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"

postgresql.yml

version: '2'
services:
  gestao-app:
    image: gestao
    environment:
      - _JAVA_OPTIONS=-Xmx512m -Xms256m
      - SPRING_PROFILES_ACTIVE=prod,swagger
      - MANAGEMENT_METRICS_EXPORT_PROMETHEUS_ENABLED=true
      - SPRING_DATASOURCE_URL=jdbc:postgresql://gestao-postgresql:5432/mydb
      - JHIPSTER_SLEEP=30 # gives time for other services to boot before the application
    ports:
      - 8080:8080
  gestao-postgresql:
    extends:
      file: postgresql.yml
      service: gestao-postgresql

application-prod.yml

version: '2'
services:
  gestao-postgresql:
    image: postgres:11.3
    volumes:
      - ~/volumes/jhipster/Gestao/postgresql/:/var/lib/postgresql/data/
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=1234
      - POSTGRES_DB=mydb
    ports:
      - 5432:5432

1 个答案:

答案 0 :(得分:0)

在jdbc连接URL中,应使用postgres服务名称(gestao-postgresql)代替localhost。