我有尝试在docker中托管的Django应用。在站立django应用之前,我无法启动我的postgres服务器。这是我的docker-compose.yaml

version: '3'
services:
  flyway:
    image: boxfuse/flyway
    command: -url=jdbc:postgresql://db/dbname -schemas=schemaName -user=user -password=pwd migrate
    volumes:
      - ./flyway:/flyway/sql
    depends_on:
      - db
  db:
    image: postgres:9.6
    restart: always
    ports:
      - 5432:5432
    environment:
    - POSTGRES_PASSWORD=pwd
    healthcheck:
      test: "pg_isready -q -U postgres"
  app:
    image: myimage
    ports:
      - 8000:8000

服务dbapp似乎都可以很好地站立,但是我无法使用flyway提升postgres默认值。这是我遇到的错误:
flyway_1  | SEVERE: Connection error:
flyway_1  | org.postgresql.util.PSQLException: Connection to db:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

ERROR:
flyway_1  | Unable to obtain connection from database (jdbc:postgresql://db/dbname) for user 'user': Connection to db:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

我找不到如何在Postgres中使用flyway的好例子。我该如何开始工作呢? TIA

最佳答案

我想,原因是这样的事实:depends_on服务的flyway实际上并不检查db-container中的数据库是否已启动并正在运行,而是检查了容器是否已启动。这是完全不同的-容器中的数据库正在启动并且尚未接受连接时,容器可以启动并运行。

在这种情况下,您应该指定进行健康检查,以确保您的数据库正在接受连接。您甚至可以在o​​jit_a中找到使用PostgreSQL进行操作的示例。

07-24 17:28
查看更多