flyway / flyway-docker

Official Flyway Docker images

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No error messages posted if connection fails

jplumhoff opened this issue · comments

Hope this saves some time for someone else... While attempting to use a flyway container in docker-compose, I recently ran into a self-imposed problem where I had forgotten to add the networks parameter to my flyway container:

networks:
  some-net:
    driver: bridge

services:
  postgres:
    image: postgres:14.1
    networks:
      - some-net
    environment:
        - POSTGRES_USER=someuser
        - POSTGRES_PASSWORD=somepassword
    ports:
    - '5432:5432'
    volumes:
      # copy the sql script to create database
      - ./create_db.sql:/docker-entrypoint-initdb.d/create_tables.sql
    healthcheck:
      test: [ "CMD", "pg_isready", "-q", "-d", "somedb", "-U", "someuser" ]
      interval: 10s
      timeout: 5s
      retries: 5

  flyway:
    image: flyway/flyway:9.0.1
    #uncomment the next two lines to fix the problem
    #networks:
    #  - some-net
    command: -url=jdbc:postgresql://postgres:5432/somedb -schemas=repo -user=someuser -password=somepassword -connectRetries=60 migrate   
    volumes:
      - ./my_migrations:/flyway/sql
    depends_on:
      postgres:
        condition: service_healthy
    restart: on-failure

The flyway container started, but emitted no log messages and just appeared frozen. I would have expected some sort of timeout or error message to help diagnose the error. In the end, I had to run the flyway container using docker run... to see the actual error:

SQL State  : 08001
Error Code : 0
Message    : The connection attempt failed.

Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
Caused by: java.net.UnknownHostException: postgres
commented

There's a related issue and this comment describes what is happening - compose seems to be hiding the logs sometimes, but run doesn't

Closing this till further activity as there isn't much we can do at this point