Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 与cassandra和docker py的连接被拒绝错误_Python_Python 2.7_Cassandra_Docker_Dockerpy - Fatal编程技术网

Python 与cassandra和docker py的连接被拒绝错误

Python 与cassandra和docker py的连接被拒绝错误,python,python-2.7,cassandra,docker,dockerpy,Python,Python 2.7,Cassandra,Docker,Dockerpy,因此,基本上我正在尝试运行一个cassandra docker实例(2.1),并按照中的说明运行cqlsh命令 或 手动操作一切正常,但在尝试使用docker py自动化此流程时,我遇到了运行cqlsh shell的问题。 我无法从链接容器中对正在运行的cassandra docker容器执行cqlsh shell和运行命令。下面,我提供了代码和我为使cqlsh shell工作而尝试的各种命令组合得到的响应。如有任何提示/建议/答案,我们将不胜感激 这是我正在使用的代码 import docke

因此,基本上我正在尝试运行一个cassandra docker实例(2.1),并按照中的说明运行cqlsh命令

手动操作一切正常,但在尝试使用docker py自动化此流程时,我遇到了运行cqlsh shell的问题。 我无法从链接容器中对正在运行的cassandra docker容器执行cqlsh shell和运行命令。下面,我提供了代码和我为使cqlsh shell工作而尝试的各种命令组合得到的响应。如有任何提示/建议/答案,我们将不胜感激

这是我正在使用的代码

import docker

host_config = client.create_host_config(port_bindings={
        9042: 9042,
        7199: 7199,
        7001: 7001
    }
)

ctr = client.create_container('cassandra:2.1', name='some-cassandra',
                                  ports=[9042, 7199, 7001],
                                  host_config=host_config
                                  )
# start cassandra container
ctr_id = ctr['Id']

link_path = 'some-cassandra'
link_alias1 = 'cassandra'

link_ctr = client.create_container(
    'cassandra:2.1',
    command=['/bin/sh'],
    host_config=client.create_host_config(
        links={link_path: link_alias1},            
    ),
    stdin_open=True,
    detach=True,
    tty=True
)
r=client.start(ctr)

# start another linked container

r=client.start(link_ctr["Id"])

# Try to invoke cqlsh shell to run some commands

for x in [["cat /etc/hosts"], ['cqlsh',"cassandra"], ['cqlsh', '$CASSANDRA_PORT_9042_TCP_ADDR'], ['cqlsh','172.17.0.4', '9042'], ['cqlsh','172.17.0.4', '9160'], ['cqlsh','172.17.0.4', '7199']]:
    res = client.exec_create(link_ctr["Id"], cmd=x)
    exec_log = client.exec_start(res)
    print exec_log

client.stop(link_ctr["Id"])
client.stop(ctr)
client.remove_container(ctr)
client.remove_container(link_ctr)
这是我得到的结果

cat/etc/hosts/ ['cqlsh',“cassandra”] ['cqlsh','$CASSANDRA_PORT_9042_TCP_ADDR'] [cqlsh'、'172.17.0.4'、'9042'] [cqlsh'、'172.17.0.4'、'9160'] [cqlsh'、'172.17.0.4'、'7199']
我使用cassandra drover for python解决了这个问题

原始google组线程

python的Cassandra驱动程序

$ docker run -it --link some-cassandra:cassandra --rm cassandra cqlsh cassandra
import docker

host_config = client.create_host_config(port_bindings={
        9042: 9042,
        7199: 7199,
        7001: 7001
    }
)

ctr = client.create_container('cassandra:2.1', name='some-cassandra',
                                  ports=[9042, 7199, 7001],
                                  host_config=host_config
                                  )
# start cassandra container
ctr_id = ctr['Id']

link_path = 'some-cassandra'
link_alias1 = 'cassandra'

link_ctr = client.create_container(
    'cassandra:2.1',
    command=['/bin/sh'],
    host_config=client.create_host_config(
        links={link_path: link_alias1},            
    ),
    stdin_open=True,
    detach=True,
    tty=True
)
r=client.start(ctr)

# start another linked container

r=client.start(link_ctr["Id"])

# Try to invoke cqlsh shell to run some commands

for x in [["cat /etc/hosts"], ['cqlsh',"cassandra"], ['cqlsh', '$CASSANDRA_PORT_9042_TCP_ADDR'], ['cqlsh','172.17.0.4', '9042'], ['cqlsh','172.17.0.4', '9160'], ['cqlsh','172.17.0.4', '7199']]:
    res = client.exec_create(link_ctr["Id"], cmd=x)
    exec_log = client.exec_start(res)
    print exec_log

client.stop(link_ctr["Id"])
client.stop(ctr)
client.remove_container(ctr)
client.remove_container(link_ctr)
172.17.0.5  5da36a67e228
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.4  cassandra 000c295fb3c7 some-cassandra
Connection error: ('Unable to connect to any servers', {'cassandra': error(111, "Tried connecting to [('172.17.0.4', 9042)]. Last error: Connection refused")})
Connection error: ('Unable to connect to any servers', {'$CASSANDRA_PORT_9042_TCP_ADDR': gaierror(-2, 'Name or service not known')})
Connection error: ('Unable to connect to any servers', {'172.17.0.4': error(111, "Tried connecting to [('172.17.0.4', 9042)]. Last error: Connection refused")})
Connection error: ('Unable to connect to any servers', {'172.17.0.4': error(111, "Tried connecting to [('172.17.0.4', 9160)]. Last error: Connection refused")})
Connection error: ('Unable to connect to any servers', {'172.17.0.4': error(111, "Tried connecting to [('172.17.0.4', 7199)]. Last error: Connection refused")})