1

I'm working with liquibase migration tool, it is working fine through terminal (update the table in scylla db).

Now I want to dockerize it, for this I do the following steps:

  1. Create liquibase.properties file:

    changeLogFile: changelog.sql

    url: jdbc:cassandra://localhost:9041/mykeyspace

    driver: com.simba.cassandra.jdbc42.Driver

    defaultSchemaName: mykeyspace

My scylladb container is running at port 9041 with keyspace 'mykeyspace'

  1. Create changelog.sql file:

     --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. Create docker compose file:

version: '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"]

When I run command 'docker-compose -f docker-compose.yml up' It generate an error:

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

How can I remove this error ?

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
Asif
  • 198
  • 10
  • So to clarify, you have a scyllaDB container, and now you are adding another container that has the liquibase in it and from the syntax, I'm assuming you're using docker compose? – Rick Rackow Aug 17 '23 at 08:38
  • Yes Rick Rackow You are right . ScyllaDB container is running and now I'm trying to run another container having liquibase using Docker-compose – Asif Aug 17 '23 at 09:55
  • 1
    ok then you can't connect to localhost. --> https://stackoverflow.com/a/76882431/6336357 – Rick Rackow Aug 17 '23 at 10:05
  • Thanks for your precious time. I Tried to connect it using IP:Port but nothing happened such as url: jdbc:cassandra://172:19:02:9041/mykeyspace url: jdbc:cassandra://scylla-node:9041/mykeyspace but still getting same connection error. – Asif Aug 17 '23 at 11:02
  • isn't the default port for scylla 9042? how did you specify a different port? – Rick Rackow Aug 17 '23 at 11:44
  • While creating scyllaDB container I specified the port, such as ` scylla-node1: container_name: scylla-node1 image: scylladb/scylla:4.5.0 ports: - 9041:9042` (here is some part of docker-compose where i set the port 9041) – Asif Aug 17 '23 at 11:53
  • yeah no. that is the port you're mapping to on the host. I explained that in the answer i linked right under the code snippet – Rick Rackow Aug 17 '23 at 11:54
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/254942/discussion-between-asif-and-rick-rackow). – Asif Aug 17 '23 at 12:07

2 Answers2

1

You are trying to connect two containers, not two services on the host. If you use localhost in a container it is referring to inside the container. Inside your liquibase container nothing is listening on port 9041.

The right way to do this is (when using docker-compose), by referencing the container that runs scylla directly. In your case that is scylla node.

Now it is also important to note, that when doing that, you need to use the port that scylla is listening on, not the port that you expose to the host. For Scylla DB that is port 9042 as you can read in the documentation.

Your adjusted properties part would look like this:

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

Rick Rackow
  • 1,490
  • 8
  • 19
0

As the error states, the driver threw a TransportException because there is no connectivity to localhost in the Scylla container, therefore "Cannot connect":

... com.simba.cassandra.shaded.datastax.driver.core.exceptions.TransportException: \
      [localhost/127.0.0.1:9041] Cannot connect ...

By definition, localhost is local to the host so it can only be accessed withIN that operating system instance (OSI).

To access services from "outside" the container, you need to expose (publish) the port to the outside world using the --publish (or -p) flag.

Once you've exposed the CQL port, you will need configure the JDBC URL with with the Scylla container's hostname or IP that is accessible/reachable/routable from the Liquibase container. For details, see Docker Networking overview.

As a side note, the Simba JDBC driver for Apache Cassandra is proprietary software (not open-source) so its use is subject to terms and conditions.

Under the license terms, the Simba JDBC driver can only be used with (1) DataStax software and services such as DataStax Enterprise or (2) Apache Cassandra. It is otherwise a breach of license to use the driver to connect to other software or services including variants which are Cassandra-compatible. Cheers!

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23