简体   繁体   English

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

[英]Connection refused error with cassandra and docker-py

so basically I am trying to run a cassandra docker instance (2.1) and run cqlsh commands following instructions from https://hub.docker.com/_/cassandra/ . 所以基本上我试图按照https://hub.docker.com/_/cassandra/中的说明运行cassandra docker实例(2.1)并运行cqlsh命令。

$ docker run --name some-cassandra -d cassandra:2.1
$ docker run -it --link some-cassandra:cassandra --rm cassandra sh -c 'exec cqlsh "$CASSANDRA_PORT_9042_TCP_ADDR"'

or 要么

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

Manually everything works fine as expected , but when trying to automate this flow with docker-py ,I am having issues with running cqlsh shell. 手动,一切都按预期工作,但尝试使用docker-py自动化此流程时,我在运行cqlsh shell时遇到问题。 I am not able to execute the cqlsh shell and run commands against my running cassandra docker container from my linked container. 我无法执行cqlsh shell并从链接的容器中对正在运行的cassandra docker容器运行命令。 Below, I have provided the code and the response I get for various combination of commands I have tried to get the cqlsh shell working. 在下面,我提供了代码和我为使cqlsh shell工作而尝试的各种命令组合所获得的响应。 Any hints/suggestions/answers is highly appreciated. 任何提示/建议/答案都受到高度赞赏。

Here is the code I am using. 这是我正在使用的代码。

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)

and here is the output I am getting 这是我得到的输出

cat /etc/hosts/ 猫/ etc / hosts /

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

['cqlsh',"cassandra"] [ 'cqlsh', “卡桑德拉”]

Connection error: ('Unable to connect to any servers', {'cassandra': error(111, "Tried connecting to [('172.17.0.4', 9042)]. Last error: Connection refused")})

['cqlsh', '$CASSANDRA_PORT_9042_TCP_ADDR'] ['cqlsh','$ CASSANDRA_PORT_9042_TCP_ADDR']

Connection error: ('Unable to connect to any servers', {'$CASSANDRA_PORT_9042_TCP_ADDR': gaierror(-2, 'Name or service not known')})

['cqlsh','172.17.0.4', '9042'] ['cqlsh','172.17.0.4','9042']

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")})

['cqlsh','172.17.0.4', '9160'] ['cqlsh','172.17.0.4','9160']

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")})

['cqlsh','172.17.0.4', '7199'] ['cqlsh','172.17.0.4','7199']

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")})

I solved this issue by using cassandra drover for python. 我通过将cassandra drover用于python解决了这个问题。

original google group thread https://groups.google.com/forum/#!topic/docker-dev/LUEuHWy4GVU 原始的Google组线程https://groups.google.com/forum/#!topic/docker-dev/LUEuHWy4GVU

Cassandra driver for python https://datastax.github.io/python-driver/ 适用于python的Cassandra驱动程序https://datastax.github.io/python-driver/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM