简体   繁体   English

Docker - Elasticsearch - 无法建立新连接:[Errno 111] Connection refused',))

[英]Docker - Elasticsearch - Failed to establish a new connection: [Errno 111] Connection refused',))

I'm using docker-compose to run python flask app and elasticsearch services in a Linode server. 我正在使用docker-compose在Linode服务器中运行python flask app和elasticsearch服务。

Here is my docker-compose.yml 这是我的docker-compose.yml

version: '2'

services:
  elasticsearch:
    build: config/elastic/
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xms1g -Xmx1g"
    networks:
      - docker_lr
  web:
    build: .
    ports:
      - "8000:8000"
    networks:
      - docker_lr
    depends_on:
      - elasticsearch

networks:
  docker_lr:
    driver: bridge

Here is the elasticsearch Dockerfile 这是elasticsearch Dockerfile

FROM elasticsearch:5

ENV ES_JAVA_OPTS="-Des.path.conf=/etc/elasticsearch"

CMD ["-E", "network.host=0.0.0.0", "-E", "discovery.zen.minimum_master_nodes=1"]

Here is the Dockerfile for web https://github.com/mysticmode/LibreRead/blob/master/Dockerfile 这是用于webDockerfile https://github.com/mysticmode/LibreRead/blob/master/Dockerfile

Both the services are running, which I can check in the browser with my :8000 and :9200 这两个服务都在运行,我可以使用my:8000和9200在浏览器中查看

But I couldn't connect to elasticsearch at :9200 from my python application code. 但我无法从我的python应用程序代码连接到:9200的elasticsearch。

r = requests.get('http://localhost:9200/lr_index/book_info/_search', data=payload)

It is showing this error 它显示此错误

ConnectionError: HTTPConnectionPool(host='localhost', port=9200): Max retries exceeded with url: /lr_index/book_info/_search (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f5b13872250>: Failed to establish a new connection: [Errno 111] Connection refused',))

Could someone guide me? 有人可以指导我吗? Thanks! 谢谢!

Try this: 试试这个:

r = requests.get('http://elasticsearch:9200/lr_index/book_info/_search', data=payload)

You are running the python code in web container right? 你正在web容器中运行python代码吗? localhost refers to the same container's loopback interface. localhost引用同一容器的loopback接口。

Using userdefined networks that implement DNS for containers in the same network. 使用userdefined networks实现DNS为同一网络中的容器。 That's why you can call elasticsearch container by its name. 这就是为什么你可以通过名字调用elasticsearch容器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 请求 - Python - 无法建立新连接:[Errno 111] 连接被拒绝 - Requests - Python - Failed to establish a new connection: [Errno 111] Connection refused Docker build pytest:无法建立新连接:[Errno 111]连接被拒绝 - Docker build pytest :Failed to establish a new connection: [Errno 111] Connection refused 最大重试次数超过 url:无法建立新连接:[Errno 111] 连接被拒绝' - Max retries exceeded with url: Failed to establish a new connection: [Errno 111] Connection refused' 连接错误(&#39;<urllib3.connection.HTTPSConnection object at 0x7f3a5d760390> : 建立新连接失败: [Errno 111] 连接被拒绝&#39;) - ConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f3a5d760390>: Failed to establish a new connection: [Errno 111] Connection refused') urllib3 - 无法建立新连接:[Errno 111] - urllib3 - Failed to establish a new connection: [Errno 111] 新连接错误(<urllib3.connection.HTTPConnection object at 0x7f09b9f0a7c0> : 建立新连接失败: [Errno 111] 连接被拒绝) - NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f09b9f0a7c0>: Failed to establish a new connection: [Errno 111] Connection refused) ConnectionRefusedError:[Errno 111]连接被拒绝 - ConnectionRefusedError: [Errno 111] Connection refused Mysql([Errno 111] 连接被拒绝)”) - Mysql ([Errno 111] Connection refused)") GraphQL:[Errno 111] 连接被拒绝 - GraphQL: [Errno 111] Connection refused 套接字连接被拒绝 [Errno 111] - Socket Connection Refused [Errno 111]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM