Python Elasticsearch超时,docker容器之间的curl工作正常

我有两个使用docker桥networking的docker集装箱。

一个容器运行Elasticsearch 2.6.1。 另一个有一个用一些python代码运行的Ubuntu镜像。

无论我想要执行的弹性search查询,它都可以完美地使用来自Ubuntu容器shell的Curl。

当我尝试使用Python-Elasticsearch库在ubuntu容器中做同样的事情时,我得到一个超时错误:

Traceback (most recent call last): File "test_elastics.py", line 11, in <module> res = es.index(index="test-index", doc_type='tweet', id=1, body=doc) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 69, in _wrapped return func(*args, params=params, **kwargs) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 279, in index _make_path(index, doc_type, id), params=params, body=body) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 329, in perform_request status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py", line 102, in perform_request raise ConnectionTimeout('TIMEOUT', str(e), e) elasticsearch.exceptions.ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host=u'172.17.0.1', port=9200): Read timed out. (read timeout=30)) 

我在RHEL发行版上使用docker 1.7.1。

运行最新的Docker CE 17.06的Macbook上的相同容器运行得非常完美。

我不明白发生了什么,如果Curl能够达到elasticsearch为什么不urllib?

感谢您的帮助。

PS:奇怪的是,似乎python脚本能够创build索引…

更新1

我用于elasticsearch容器的docker镜像是这个https://github.com/partlab/docker/tree/master/ubuntu-elasticsearch

我将这两行添加到elasticsearch.yml:

 script.inline: true script.indexed: true 

我使用这个命令行来运行容器:

 sudo docker run -d -p 9200:9200 -p 9300:9300 --name cca_elasticsearch -v /home/myhome/elastic_data dc6da47c125a 

更新2

我试过的curl请求:

 foo@b8b74b6e5609:~$ curl 172.17.0.1:9200 { "name" : "Puff Adder", "cluster_name" : "elasticsearch", "cluster_uuid" : "s58rhxIuRKqUjEJF-ckOIQ", "version" : { "number" : "2.4.6", "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd", "build_timestamp" : "2017-07-18T12:17:44Z", "build_snapshot" : false, "lucene_version" : "5.5.4" }, "tagline" : "You Know, for Search" } 

另一个检查索引:

 foo@b8b74b6e5609:~$ curl '172.17.0.1:9200/_cat/indices?v' health status index pri rep docs.count docs.deleted store.size pri.store.size 

我尝试了这个新的失败,对不起,在我的testing中,

 foo@b8b74b6e5609:~$ curl -XPUT '172.17.0.1:9200/megacorp/employee/1?pretty' -H 'Content-Type: application/json' -d' { "first_name" : "John", "last_name" : "Smith", "age" : 25, "about" : "I love to go rock climbing", "interests": [ "sports", "music" ] } ' { "error" : { "root_cause" : [ { "type" : "unavailable_shards_exception", "reason" : "[megacorp][3] primary shard is not active Timeout: [1m], request: [index {[megacorp][employee][1], source[ { \"fir st_name\" : \"John\", \"last_name\" : \"Smith\", \"age\" : 25, \"about\" : \"I love to go rock climbing\", \"interests\": [ \"sports \", \"music\" ] } ]}]" } ], "type" : "unavailable_shards_exception", "reason" : "[megacorp][3] primary shard is not active Timeout: [1m], request: [index {[megacorp][employee][1], source[ { \"first _name\" : \"John\", \"last_name\" : \"Smith\", \"age\" : 25, \"about\" : \"I love to go rock climbing\", \"interests\": [ \"sports\" , \"music\" ] } ]}]" }, "status" : 503 } 

这似乎与我的Python代码相同的问题:

 from datetime import datetime from elasticsearch import Elasticsearch es = Elasticsearch('172.17.0.1:9200') doc = { 'author': 'kimchy', 'text': 'Elasticsearch: cool. bonsai cool.', 'timestamp': datetime.now(), } res = es.index(index="test-index", doc_type='tweet', id=1, body=doc) print(res['created']) 

更新3

我的elasticsearch docker发生了一些问题,我只是注意到了这一点。

以下是该容器的docker日志的尾部:

https://paste.atilla.org/paste/XE95RD/raw