无法从golang连接到docker上的elasticsearch

时间:2017-11-17 00:59:15

标签: docker elasticsearch

我正在使用olivere的弹性go库(https://godoc.org/gopkg.in/olivere/elastic.v5)创建与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容器中卷曲它。但是,go代码(在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已关闭,不确定是否与此有关。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

修改/ etc/elasticsearch/elasticsearch.yml添加以下行:

network.host: 0.0.0.0

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

This question

可能重复