admin管理员组

文章数量:1122832

So I have a problem where I'm using docker-compose to setup and run my database and migrations via flyway but I'm running into an issue where the flyway container keeps throwing the following error:

2024-11-22 14:54:57 WARNING: Connection error: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

The database container I've got that working properly and its running the way I want it, I just can't seem to figure out whats going on with flyway.

Even though I'm seeing the connection refused error in my flyway logs, when I look at my logs on my mssql server I'm not seeing any connections being made at all, which makes me wonder if flyway can even see the database.

I've got the following docker-compose.yml

services:
  database:
    build:
      no_cache: true
      context: ./database/mssql
      args:
        DB_PASSWORD: ${DB_PASSWORD}
        ACCEPT_EULA: Y
    environment:
      - DB_PASSWORD=${DB_PASSWORD}
    container_name: database
    ports:
        - 1433:1433
    volumes:
      - dbdata:/var/opt/mssql
  flyway:
    image: redgate/flyway
    container_name: flyway
    command: migrate -user=${DB_USER} -password=${DB_PASSWORD} -connectRetries=60
    volumes:
      - ./database/flyway/conf/:/flyway/conf
      - ./database/flyway/sql/:/flyway/sql
    depends_on:
      - database      
volumes:
  dbdata:

and on the flyway side of things my flyway.conf looks like this:

flyway.url=jdbc:sqlserver://localhost:1433;databaseName=${DB_NAME};TrustServerCertificate=True;
flyway.defaultSchema=${DB_SCHEMA}

The thing thats confusing me is I'm basing things off this article: and I can get that solution to work the way it is, but I just can't seem to connect to the database in my own setup and I'm not sure what I'm doing wrong.

So I have a problem where I'm using docker-compose to setup and run my database and migrations via flyway but I'm running into an issue where the flyway container keeps throwing the following error:

2024-11-22 14:54:57 WARNING: Connection error: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

The database container I've got that working properly and its running the way I want it, I just can't seem to figure out whats going on with flyway.

Even though I'm seeing the connection refused error in my flyway logs, when I look at my logs on my mssql server I'm not seeing any connections being made at all, which makes me wonder if flyway can even see the database.

I've got the following docker-compose.yml

services:
  database:
    build:
      no_cache: true
      context: ./database/mssql
      args:
        DB_PASSWORD: ${DB_PASSWORD}
        ACCEPT_EULA: Y
    environment:
      - DB_PASSWORD=${DB_PASSWORD}
    container_name: database
    ports:
        - 1433:1433
    volumes:
      - dbdata:/var/opt/mssql
  flyway:
    image: redgate/flyway
    container_name: flyway
    command: migrate -user=${DB_USER} -password=${DB_PASSWORD} -connectRetries=60
    volumes:
      - ./database/flyway/conf/:/flyway/conf
      - ./database/flyway/sql/:/flyway/sql
    depends_on:
      - database      
volumes:
  dbdata:

and on the flyway side of things my flyway.conf looks like this:

flyway.url=jdbc:sqlserver://localhost:1433;databaseName=${DB_NAME};TrustServerCertificate=True;
flyway.defaultSchema=${DB_SCHEMA}

The thing thats confusing me is I'm basing things off this article: https://dev.to/leopardorossi/sql-server-and-flyway-a-docker-approach-kdj and I can get that solution to work the way it is, but I just can't seem to connect to the database in my own setup and I'm not sure what I'm doing wrong.

Share Improve this question asked Nov 22, 2024 at 23:12 MarqueoneMarqueone 1,2132 gold badges16 silver badges35 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Problem solved!

the problem was not using the correct name in my flyway.conf

flyway.url=jdbc:sqlserver://localhost:1433;databaseName=${DB_NAME};TrustServerCertificate=True;

this configuration was incorrect, and instead should have been:

flyway.url=jdbc:sqlserver://database:1433;databaseName=${DB_NAME};TrustServerCertificate=True;

I needed to use database from the docker-compose because thats what the database configuration was configured to use.

本文标签: Connection refused when trying to migrate database with flyway via dockercomposeStack Overflow