Dockerized Liquibase 无法连接到 Dockerized Scylladb,出现“DatabaseException:无法创建连接”

问题描述 投票:0回答:1

我正在使用 liquibase 迁移工具,它通过终端工作正常(更新 scylla db 中的表)。

现在我想对其进行 dockerize,为此我执行以下步骤:

  1. 创建liquibase.properties文件:

    changeLogFile:changelog.sql

    网址:jdbc:cassandra://localhost:9041/mykeyspace

    驱动程序:com.simba.cassandra.jdbc42.Driver

    默认模式名称:mykeyspace

我的 scyladb 容器正在端口 9041 运行,密钥空间为“mykeyspace”

  1. 创建changelog.sql文件:

     --liquibase formatted sql
    
     --changeset liquibase:1
     CREATE KEYSPACE IF NOT EXISTS studentkeyspace WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': 3};
    
     --changeset liquibase:2
     CREATE TABLE IF NOT EXISTS studentkeyspace.studentData (name text, Id text PRIMARY KEY, email text)
    
  2. 创建 docker compose 文件:

版本:'3'

services:
  liquibase:
    image: liquibase/liquibase:4.1.1
    container_name: liquibasecontainer
    volumes:
      - ./changelogs:/liquibase/changelogs
      - ./liquibase.properties:/liquibase/liquibase.properties
      - /home/asif/Liquibase/liquibase-4.1.1/lib:/liquibase/lib
    command: ["--defaultsFile=/liquibase/liquibase.properties", "update"]

当我运行命令“docker-compose -f docker-compose.yml up”时 它会产生错误:

Unexpected error running Liquibase: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to jdbc:cassandra://localhost:9041/mykeyspace with driver com.simba.cassandra.jdbc42.Driver.  [Simba][CassandraJDBCDriver](500150) Error setting/closing connection: All host(s) tried for query failed (tried: localhost/127.0.0.1:9041 (com.simba.cassandra.shaded.datastax.driver.core.exceptions.TransportException: [localhost/127.0.0.1:9041] Cannot connect)).
liquibasecontainer | For more information, please use the --logLevel flag
liquibasecontainer exited with code 255

如何消除此错误?

docker cassandra liquibase scylla cassandra-jdbc-driver
1个回答
1
投票

您正在尝试连接两个容器,而不是主机上的两个服务。如果您在容器中使用

localhost
,则它指的是容器内部。在您的
liquibase
容器内,没有任何内容正在侦听端口 9041。

正确的方法是(使用 docker-compose 时),通过引用直接运行 scylla 的容器。在你的情况下,那就是

scylla node

现在还需要注意的是,执行此操作时,您需要使用 scylla 正在侦听的端口,而不是暴露给主机的端口。对于 Scylla DB,端口为 9042,您可以阅读文档中

您调整后的

properties
部分将如下所示:

url: jdbc:cassandra://scylla-node:9042/mykeyspace

© www.soinside.com 2019 - 2024. All rights reserved.