无法使用cqlsh连接到cassandra docker

我运行Cassandra docker容器:

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

但是,我没有从localhost与docker容器连接:

$sqlsh
Traceback (most recent call last):
  File "/usr/sbin/cqlsh",line 2067,in 

所以,我没有从localhost PHP-driver连接.

我怎么能用我的PHP脚本连接cassandra docker& cqlsh?

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

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

添加信息

如果运行conteiner为:

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 run命令更改为:

docker pull cassandra
docker 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

从程序,您必须连接到Thrift端口.请按照http://support.qualityunit.com/942764-Example-of-PHP-application-readingwriting-to-Cassandra中的示例进行操作
在上面的示例中,要从运行容器的同一台机器连接到cassandra容器,您仍然可以使用相同的TSocket(‘127.0.0.1’,9160).

如果您计划从另一台计算机进行连接,则必须使用TSocket(“IP /域名”,9160),IP /域名是运行docker容器的计算机的标识符.

如果您的程序位于同一台机器上的另一个docker容器中,首先您必须链接容器,然后您可以使用TSocket(‘别名’,别名是您的链接名称.

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

相关文章

Docker是什么Docker是 Docker.Inc 公司开源的一个基于 LXC技...
本文为原创,原始地址为:http://www.cnblogs.com/fengzheng...
镜像操作列出镜像:$ sudo docker imagesREPOSITORY TAG IMA...
本文原创,原文地址为:http://www.cnblogs.com/fengzheng/p...
在 Docker 中,如果你修改了一个容器的内容并希望将这些更改...
在Docker中,--privileged 参数给予容器内的进程几乎相同的权...