无法连接到golang的docker上的elasticsearch

我使用的是橄榄球的弹性去库( https://godoc.org/gopkg.in/olivere/elastic.v5 )创build一个连接到elasticsearch像这样:

addr = "http://172.17.0.2:9200" client, err := elastic.NewClient(elastic.SetURL(addr)) 

并得到这个错误:

 health check timeout: no Elasticsearch node available 

Elasticsearch在Docker容器中运行,我可以从我的本地机器和Docker容器中进行curl。 但是,代码(运行在Docker容器上)无法连接到它。

 curl -s -XGET 'http://172.17.0.2:9200/_nodes/http?pretty=1' { "_nodes" : { "total" : 1, "successful" : 1, "failed" : 0 }, "cluster_name" : "elasticsearch", "nodes" : { "pGBN2DBISgSZ8hd9lFgmHw" : { "name" : "pGBN2DB", "transport_address" : "127.0.0.1:9300", "host" : "127.0.0.1", "ip" : "127.0.0.1", "version" : "5.6.4", "build_hash" : "8bbedf5", "roles" : [ "master", "data", "ingest" ], "http" : { "bound_address" : [ "0.0.0.0:9200" ], "publish_address" : "172.17.0.2:9200", "max_content_length_in_bytes" : 104857600 } } } } 

我正在使用Docker for Mac。 发布地址和IP已closures,不确定是否与此有关。 将不胜感激任何帮助!

编辑/ etc/elasticsearch/elasticsearch.yml添加以下行:

 network.host: 0.0.0.0 

这将允许来自其他IP的连接。

这个问题可能重复