gpt4 book ai didi

docker - 无法从Golang连接到Docker上的Elasticsearch

转载 作者:行者123 更新时间:2023-12-02 19:34:28 26 4
gpt4 key购买 nike

我正在使用Olivere的elastic 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容器中 curl 它。但是,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已关闭,不确定是否与此有关。将不胜感激!

最佳答案

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

network.host: 0.0.0.0

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

This question的可能重复项

关于docker - 无法从Golang连接到Docker上的Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47341662/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com