无法使用cqlsh连接到cassandra docker

我正在运行Cassandradocker集装箱:

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 [::]:* 

从本地cqlsh连接到C *是好的:

 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. 

我安装本地的cqlsh:

 $cqlsh --version cqlsh 4.1.1 

但是,我不connecton从本地主机的docker容器:

 $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 

所以,我不从localhost的PHP驱动程序连接。

我如何可以连接cassandra泊坞窗与我的PHP脚本和cqlsh?

为什么docker的端口映射到tcp6,不要tcp4? 解决

为什么本地cqlsh(版本4.1)通过9160端口连接,但docker容器cqlsh(版本5.0.1)通过9042端口连接?


添加信息

如果运行竞争者为:

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

我有听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 

但我没有与cqlsh&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 

尝试改变你的docker运行命令为:

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

这将确保docker容器映射到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容器运行,你仍然可以使用相同&#x7684;TSocket('127.0.0.1', 9160)

如果您打算从不同的机器连接,那么您必须在此使用TSocket('IP/Domain name', 9160) ,IP /域名是运行docker集装箱的机器的标识符。

如果你的PHP应用程序在同一台机器上的另一个docker容器中,首先你必须链接容器,那么你可以在TSocket('alias name', 9160)使用TSocket('alias name', 9160) ,别名是你的链接名。

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