docker - 无法从另一个容器连接到 ElasticSearch 容器
问题描述
我正在尝试使用官方apiElasticSearch
从容器连接到容器。但是,当我尝试连接到容器时,出现此错误:Golang
go-elasticsearch
Error getting response: dial tcp 172.28.0.2:9200: connect: connection refused
我认为这是容器设置中的问题?
docker-compose.yaml
version: "3"
services:
redis_server:
image: "redis"
ports:
- "6379:6379"
lambda_server:
build: .
ports:
- "8080:50051"
depends_on:
- redis_server
- elasticsearch
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.3.1
ports:
- "9200:9200"
- "9300:9300"
environment:
- xpack.security.enabled=false
- discovery.type=single-node
- http.cors.enabled=true
- http.cors.allow-origin=*
去
tlsConf := &http.Transport{
TLSClientConfig: &tls.Config{
Renegotiation: tls.RenegotiateOnceAsClient,
Certificates: []tls.Certificate{cer},
},
}
cfg := elasticsearch.Config{
Addresses: []string{
"http://elasticsearch:9200",
"http://elasticsearch:9300",
},
Transport: tlsConf,
}
elasticClient, err = elasticsearch.NewClient(cfg)
res, err := elasticClient.Info()
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
解决方案
推荐阅读
- python - netconf AuthenticationError
- uwp - 如何在 C++Winrt 中将 IStorageItem 转换为 StorageFile
- excel - Excel VBA'Selection.Filldown'复制选定单元格上方的单元格
- python - 如何在 Python 中解密 C# 的 AES 加密数据?
- python - 如何将列值(美元)归因于熊猫中的不同列
- laravel - 如何删除 Redis 中的所有键,除了在 Laravel 中以前缀开头的键
- python - 为什么我的函数会导致无限循环?
- ios - 快速同步工作任务和进度视图控制器
- mongodb - 将变量从 MongoDB 导入 MySQL
- mysql - 对于在本地 Docker 容器中运行的 mysql 数据库,用户“root”@“172.17.0.1”的访问被拒绝