1

I have created a single node ScyllaDB in docker, which is up and running, and below is my docker-compose commands: version: "3"

 services:

 scylla-node1:
   container_name: scylla-node1
   image: scylladb/scylla
   restart: always
   command: --smp 2 --memory 1500M --broadcast-rpc-address 127.0.0.1 --listen-address 0.0.0.0 
   ports: 
       - 9042:9050
   networks:
   web:

   networks:
   web:
   driver: bridge

Reading the documentation for Scylla it recommends using the DataStax C# Driver for Apache Cassandra. So, I have used this in my solution. Following the basic examples, I am struggling to get it work. Thus,

   var cluster = Cluster.Builder()
                 .AddContactPoints("0.0.0.0")
                 .Build();

  var session = cluster.Connect("sample_keyspace");

When the code reaches the Connect command it throws the following error Cassandra.NoHostAvailableException: 'All hosts tried for query failed (tried 0.0.0.0:9042: SocketException 'The requested address is not valid in its context.')'

Firstly, I can connect to Scylla through the CSQL Utility and can create a Keyspace and then run a query to confirm that the Keyspace has been created.

Is this a problem with C# Driver or am I doing something wrong?

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
Andy5
  • 2,319
  • 11
  • 45
  • 91
  • So when you run Docker, your container gets its own IP. Have you tried connecting to port 9042 on _that_ IP? You'll also need to open up that port from your container to the outside world. – Aaron Feb 07 '23 at 17:43
  • The driver by default uses port 9042 unless you specify it. I would have thought the port setting in the compose allows access to the IP and port, doesn't it? – Andy5 Feb 07 '23 at 18:55
  • Yeah, if you `EXPOSE` it in your dockerfile that's part of it. But you might also need to specify it when running the container...`docker run --name cassandra-node1 --net=cassandra_network -p 9042:9042` – Aaron Feb 07 '23 at 19:01

1 Answers1

1

This looks like a networking issue to me because your Docker container doesn't appear to be configured correctly.

The problem is that the C# driver (your application) is not able to connect to the container because there is no network connectivity. That is what this exception means:

Cassandra.NoHostAvailableException: 'All hosts tried for query failed (tried 0.0.0.0:9042: \
  SocketException 'The requested address is not valid in its context.')'

I assume "CSQL utility" is a typo. The reason you are able to connect using cqlsh is because you are most likely connecting with:

$ docker exec -it scylla-node1 cqlsh

which isn't the same as connecting remotely. To be fair I'm making an assumption as you didn't provide details.

You've configured the container with --broadcast-rpc-address 127.0.0.1 so it will only listen for client connections on localhost. This means that you can't use 0.0.0.0 as the contact point.

I've also noted that you've mapped the container port 9050 to host port 9042:

   ports: 
       - 9042:9050

By default, Cassandra listens for client connections on port 9042, not 9050. If nothing is listening on port 9050, there's nothing for the driver to connect to and will also lead to NoHostAvailableException. Cheers!

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