无法从Docker容器连接到本地Elasticsearch进程 [英] Not able to connect to local elasticsearch process from docker container

查看:70
本文介绍了无法从Docker容器连接到本地Elasticsearch进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑

我认为这是在docker进程内的localhost引用了容器自己的localhost,而不是我系统的localhost.那么如何确保当运行容器的应用程序尝试连接到容器的localhost:9200时,它实际上连接到系统的localhost:9200?

当我访问localhost:9200时,我的ES应用程序似乎正在运行.在chrome中看起来像这样:

  {名称":"H1YDvcg","cluster_name":"elasticsearch_jwan","cluster_uuid":"aAorzRYTQPOI0j_OgMGKpA",版本" : {"number":"6.8.1","build_flavor":"oss","build_type":"tar","build_hash":"1fad4e1","build_date":"2019-06-18T13:16:52.517138Z","build_snapshot":否,"lucene_version":"7.7.0","minimum_wire_compatibility_version":"5.6.0","minimum_index_compatibility_version":"5.0.0"},"tagline":您知道,要搜索"} 

我正在终端窗口中运行ES,并且在运行命令 elasticsearch 后它可以工作.

我正在使用以下命令运行docker容器:

  docker run -e DATALOADER_QUEUE ='<某些AWS SQS队列名称'\-e ES_HOST ='本地主机'\-e ES_PORT ='9200'\-e AWS_ACCESS_KEY_ID ='< somekey>'\-e AWS_SECRET_ACCESS_KEY ='< somekey>'\-e AWS_DEFAULT_REGION ='us-west-2'\<应用程序名称> 

我得到这个错误:

  requests.exceptions.ConnectionError:HTTPConnectionPool(host ='localhost',port = 9200):URL超过最大重试次数:/person/_search(由NewConnectionError('< urllib3.connection.HTTPConnection object at0x7f36e4189c90> 

任何人都知道发生了什么事吗?我不明白为什么即使ti似乎正在localhost:9200上运行也无法连接到ES.

解决方案

解决方案是在ES主机设置中使用 host.docker.internal .

我只是使用 es_client = Elasticsearch(host = _es_host,,其中es_host = host.docker.internal ,并确保在本地而不是https时使用http.>

EDIT

I think what is going on is that localhost inside the docker process refers to the container's own localhost, not my system's localhost. So how do I ensure that when the application running the container tries to connect to the container's localhost:9200, it actually connects to my system's localhost:9200?

When I visit localhost:9200, my ES application seems to be running. It looks like this in chrome:

{
  "name" : "H1YDvcg",
  "cluster_name" : "elasticsearch_jwan",
  "cluster_uuid" : "aAorzRYTQPOI0j_OgMGKpA",
  "version" : {
    "number" : "6.8.1",
    "build_flavor" : "oss",
    "build_type" : "tar",
    "build_hash" : "1fad4e1",
    "build_date" : "2019-06-18T13:16:52.517138Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

I am running ES in a terminal window and it works after I run the command elasticsearch.

I am running a docker container with this command:

docker run -e DATALOADER_QUEUE='<some aws SQS queue name'\
             -e ES_HOST='localhost'\
             -e ES_PORT='9200'\
             -e AWS_ACCESS_KEY_ID='<somekey>'\
             -e AWS_SECRET_ACCESS_KEY='<somekey>'\
             -e AWS_DEFAULT_REGION='us-west-2'\
             <application name>

and I get this error:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9200): Max retries exceeded with url: /person/_search (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f36e4189c90>

Anyone know what is going on? I don't understand why it cannot connect to ES even though ti seems to be running on localhost:9200.

解决方案

Solution was to use host.docker.internal in ES host setup.

I just used es_client = Elasticsearch(host=_es_host, where es_host = host.docker.internal and made sure to use http while local instead of https.

这篇关于无法从Docker容器连接到本地Elasticsearch进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆