[英]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 这是用于web的Dockerfile 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.