Cannot connect to cassandra docker with cqlsh

I am launching the Cassandra docker container:

docker pull cassandra
run --name cassandra -p 9042:9042 -p 9160:9160   -d cassandra  

Netstat -tpln:

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

LISTEN    -  tcp6       0      0 [::]:9160               [::]:*
LISTEN    -  tcp6       0      0 [::]:9042               [::]:*

The connection to C * from local cqlsh is Ok:

docker exec -it cassandra /bin/bash
#cqlsh
Connected to Test Cluster at 127.0.0.1:9042. 
[cqlsh 5.0.1 | Cassandra 3.1.1 | CQL spec 3.3.1 | Native protocol v4] 
Use HELP for help.
cqlsh> show host     
Connected to Test Cluster at 127.0.0.1:9042.  

I install local cqlsh:

$cqlsh --version
cqlsh 4.1.1

but I am not connecting to the docker container from localhost:

$sqlsh
Traceback (most recent call last):
  File "/usr/sbin/cqlsh", line 2067, in <module>
    main(*read_options(sys.argv[1:], os.environ))
  . . .
  File "/home/akalend/src/cqlsh_standalone/lib/thrift-python-internal-only-0.9.1.zip/thrift/transport/TSocket.py", line 103, in read
socket.error: [Errno 104] Connection reset by peer

So, I am not connecting from the php driver localhost.

How can I connect cassandra docker with my php script and cqlsh?

Why is docker mapping port for tcp6, not tcp4? Determination

Why is the local cqlsh (version 4.1) connected via port 9160, but the docker cqlsh container (version 5.0.1) connected to port 9042?


information added

If you run conteiner like:

run --name cassandra -p 127.0.0.1:9042:9042 -p 127.0.0.1:9160:9160   -d cassandra 

I have ip4 ports for ip4:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address  State       PID/Program name
tcp        0      0 127.0.0.1:9160 0.0.0.0:*       LISTEN      2454/docker-proxy
tcp        0      0 127.0.0.1:9042 0.0.0.0:*       LISTEN      2462/docker-proxy

but i don't mess with cqlsh and php

socket.error: [Errno 104] Connection reset by peer

PHP Fatal error:  Uncaught exception 'Cassandra\Exception\RuntimeException' with message 'No hosts available for the control connection' in /home/akalend/projects/test/cassa/test.php:7
Stack trace:
#0 /home/akalend/projects/test/cassa/test.php(7): Cassandra\DefaultCluster->connect('system')
#1 {main} thrown in /home/akalend/projects/test/cassa/test.php on line 7
+7
2

Docker :

docker pull cassandra
docker run --name cassandra -p 127.0.0.1:9042:9042 -p 127.0.0.1:9160:9160   -d cassandra 

- IPv4.

9160 - Thrift client API
9042 - CQL native transport port

PHP- Thrift-. , http://support.qualityunit.com/942764-Example-of-PHP-application-readingwriting-to-Cassandra. cassandra , , TSocket('127.0.0.1', 9160).

, TSocket('IP/Domain name', 9160) IP/ , -.

PHP- - , , TSocket('alias name', 9160), - , ,

try {
  // Make a connection to the Thrift interface to Cassandra
  $socket = new TSocket('127.0.0.1', 9160);
+18

, . Docker Container docker container ls , , cqlsh, docker exec it <container-id> bash ./cqlsh docker exec it <container-id> bash, cd/bin/ ./cqlsh, connection refused.

; 9042 docker-compose docker run -p 9042:9042.

0

Source: https://habr.com/ru/post/1623178/


All Articles