0

I have these entries in my docker-compose.yml

  flyway:
    container_name: flyway
    image: flyway/flyway
    command: -url=jdbc:postgresql://postgresql:5432/db_name -schemas=public -user=username -password=password -connectRetries=60 migrate -X
    volumes:
      - ./config/src/main/sql:/flyway/sql
    depends_on:
      - postgresql

  postgresql:
      container_name: postgresql
      image: postgres:10.1-alpine
      command:
        - postgres
        - '-clog_connections=yes'
        - '-clog_statement=all'
      env_file:
        - ./dev.env
      networks:
        - internal
      ports:
        - '5439:5432'
      volumes:
        - volume-postgres:/var/lib/postgresql/data

When I run docker-compose up --build flyway, I get this error

postgresql is up-to-date
Recreating flyway ... done
Attaching to flyway
flyway             | WARNING: Connection error: The connection attempt failed.
flyway             | (Caused by postgresql)
flyway             | Retrying in 1 sec...
flyway             | WARNING: Connection error: The connection attempt failed.
flyway             | (Caused by postgresql)
flyway             | Retrying in 2 sec...
flyway             | WARNING: Connection error: The connection attempt failed.
flyway             | (Caused by postgresql)
  1. How can I debug it? In some answers I see DEBUG printed in the output.
  2. What is wrong that it errors out?
Sky
  • 15
  • 4

1 Answers1

0

1.

The debug logs should be produced since you have the -X flag in the flyway command. It looks like it might be attaching to the flyway container after the initial debug logs have already been logged. You should be able to see full logs for the flyway container by running:

docker-compose logs flyway

2.

Flyway can't connect to Postgres because they're on different networks. You've configured postgresql to be on the internal network, but flyway does not have a network configured so it will be on the default network.

There's a few way you could fix this:

  • Remove the network property from postgresql so both services are on the default network, but this isn't ideal if you're relying on other services being able to reach it on internal.
  • Add flyway to the internal network.
  • Since you've mapped port 5432 on postgresql to 5439 on the host network, you could add flyway to the host network (by giving it the property network_mode: "host") and then use the address localhost:5439 to access postgresql.
Tom Smith
  • 111
  • 2