ggirtsou / cassandra-test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem

Could not connect to Cassandra from another container. nc reported port open and Cassandra was up and running in its container. Both containers were running in the same user defined network.

Solution

In gocql, do not define aggressive timeouts. Removed

cluster.Timeout = 300 // in ms
cluster.ConnectTimeout = 300 // in ms

You can connect to Cassandra from host using 127.0.0.1 9042 with cqlsh or DataGrip.

Setup

docker build -t test-cassandra .
docker-compose up -d # wait for cassandra to settle and then observe logs in tests container

Troubleshooting

$ docker run --rm -it --network test-cassandra_app_net test-cassandra bash
$ nc -vz cassandra 9042

# note the values in the config: https://github.com/ggirtsou/cassandra-test/blob/master/dev/cassandra.yaml#L612
# broadcast address: https://github.com/ggirtsou/cassandra-test/blob/master/dev/cassandra.yaml#L626

# see if Go can connect to Cassandra (has IP hardcoded in test file)
$ GO111MODULE=on CGO_ENABLED=0 go test -v ./...

From host:

# another thing you can try is to install cqlsh / DataGrip locally and try to connect
$ cqlsh 127.0.0.1 9042 cassandra -u cassandra -p cassandra --cqlversion="3.4.4" # run from host - this works!

9042 listens on IPv6, disabling TCP6 in Cassandra doesn't have any effect on this.

root@f96fd59f5db5:/# netstat -ltnp | grep -w ':9042'
tcp6       0      0 :::9042                 :::*                    LISTEN      -
  • Docker engine version: v19.03.13
  • OS: Mac

References

About


Languages

Language:Go 57.2%Language:Dockerfile 42.8%