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:
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'
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)
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 ?
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