New ConnectionError [Errno 111] Connection Refused using Docker
See original GitHub issueI have elasticsearch running in one docker container and elasticsearch-dsl installed in another docker on the same network.
I am trying to establish a connection between the two but am getting an error. Elasticsearch is up and running.
I entered the docker with elasticsearch-dsl installed.
from elasticsearch import Elasticsearch
connections.create_connections(hosts=['localhost:9200'])
client = Elasticsearch()
client.ping()
I get an error here, copied below. Is there a configuration step I’m missing?
Thanks
HEAD http://localhost:9200/ [status:N/A request:0.000s] Traceback (most recent call last): File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 141, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File “/usr/local/lib/python3.5/site-packages/urllib3/util/connection.py”, line 83, in create_connection raise err File “/usr/local/lib/python3.5/site-packages/urllib3/util/connection.py”, line 73, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “/usr/local/lib/python3.5/site-packages/elasticsearch/connection/http_urllib3.py”, line 149, in perform_request response = self.pool.urlopen(method, url, body, retries=False, headers=request_headers, **kw) File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 639, in urlopen _stacktrace=sys.exc_info()[2]) File “/usr/local/lib/python3.5/site-packages/urllib3/util/retry.py”, line 333, in increment raise six.reraise(type(error), error, _stacktrace) File “/usr/local/lib/python3.5/site-packages/urllib3/packages/six.py”, line 686, in reraise raise value File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 601, in urlopen chunked=chunked) File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 357, in _make_request conn.request(method, url, **httplib_request_kw) File “/usr/local/lib/python3.5/http/client.py”, line 1107, in request self._send_request(method, url, body, headers) File “/usr/local/lib/python3.5/http/client.py”, line 1152, in _send_request self.endheaders(body) File “/usr/local/lib/python3.5/http/client.py”, line 1103, in endheaders self._send_output(message_body) File “/usr/local/lib/python3.5/http/client.py”, line 934, in _send_output self.send(msg) File “/usr/local/lib/python3.5/http/client.py”, line 877, in send self.connect() File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 166, in connect conn = self._new_conn() File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 150, in _new_conn self, “Failed to establish a new connection: %s” % e) urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f08652ead68>: Failed to establish a new connection: [Errno 111] Connection refused HEAD http://localhost:9200/ [status:N/A request:0.000s] Traceback (most recent call last): File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 141, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File “/usr/local/lib/python3.5/site-packages/urllib3/util/connection.py”, line 83, in create_connection raise err File “/usr/local/lib/python3.5/site-packages/urllib3/util/connection.py”, line 73, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “/usr/local/lib/python3.5/site-packages/elasticsearch/connection/http_urllib3.py”, line 149, in perform_request response = self.pool.urlopen(method, url, body, retries=False, headers=request_headers, **kw) File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 639, in urlopen _stacktrace=sys.exc_info()[2]) File “/usr/local/lib/python3.5/site-packages/urllib3/util/retry.py”, line 333, in increment raise six.reraise(type(error), error, _stacktrace) File “/usr/local/lib/python3.5/site-packages/urllib3/packages/six.py”, line 686, in reraise raise value File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 601, in urlopen chunked=chunked) File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 357, in _make_request conn.request(method, url, **httplib_request_kw) File “/usr/local/lib/python3.5/http/client.py”, line 1107, in request self._send_request(method, url, body, headers) File “/usr/local/lib/python3.5/http/client.py”, line 1152, in _send_request self.endheaders(body) File “/usr/local/lib/python3.5/http/client.py”, line 1103, in endheaders self._send_output(message_body) File “/usr/local/lib/python3.5/http/client.py”, line 934, in _send_output self.send(msg) File “/usr/local/lib/python3.5/http/client.py”, line 877, in send self.connect() File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 166, in connect conn = self._new_conn() File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 150, in _new_conn self, “Failed to establish a new connection: %s” % e) urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f086504f0f0>: Failed to establish a new connection: [Errno 111] Connection refused HEAD http://localhost:9200/ [status:N/A request:0.000s] Traceback (most recent call last): File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 141, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File “/usr/local/lib/python3.5/site-packages/urllib3/util/connection.py”, line 83, in create_connection raise err File “/usr/local/lib/python3.5/site-packages/urllib3/util/connection.py”, line 73, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “/usr/local/lib/python3.5/site-packages/elasticsearch/connection/http_urllib3.py”, line 149, in perform_request response = self.pool.urlopen(method, url, body, retries=False, headers=request_headers, **kw) File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 639, in urlopen _stacktrace=sys.exc_info()[2]) File “/usr/local/lib/python3.5/site-packages/urllib3/util/retry.py”, line 333, in increment raise six.reraise(type(error), error, _stacktrace) File “/usr/local/lib/python3.5/site-packages/urllib3/packages/six.py”, line 686, in reraise raise value File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 601, in urlopen chunked=chunked) File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 357, in _make_request conn.request(method, url, **httplib_request_kw) File “/usr/local/lib/python3.5/http/client.py”, line 1107, in request self._send_request(method, url, body, headers) File “/usr/local/lib/python3.5/http/client.py”, line 1152, in _send_request self.endheaders(body) File “/usr/local/lib/python3.5/http/client.py”, line 1103, in endheaders self._send_output(message_body) File “/usr/local/lib/python3.5/http/client.py”, line 934, in _send_output self.send(msg) File “/usr/local/lib/python3.5/http/client.py”, line 877, in send self.connect() File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 166, in connect conn = self._new_conn() File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 150, in _new_conn self, “Failed to establish a new connection: %s” % e) urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f086504f1d0>: Failed to establish a new connection: [Errno 111] Connection refused HEAD http://localhost:9200/ [status:N/A request:0.000s] Traceback (most recent call last): File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 141, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File “/usr/local/lib/python3.5/site-packages/urllib3/util/connection.py”, line 83, in create_connection raise err File “/usr/local/lib/python3.5/site-packages/urllib3/util/connection.py”, line 73, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “/usr/local/lib/python3.5/site-packages/elasticsearch/connection/http_urllib3.py”, line 149, in perform_request response = self.pool.urlopen(method, url, body, retries=False, headers=request_headers, **kw) File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 639, in urlopen _stacktrace=sys.exc_info()[2]) File “/usr/local/lib/python3.5/site-packages/urllib3/util/retry.py”, line 333, in increment raise six.reraise(type(error), error, _stacktrace) File “/usr/local/lib/python3.5/site-packages/urllib3/packages/six.py”, line 686, in reraise raise value File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 601, in urlopen chunked=chunked) File “/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py”, line 357, in _make_request conn.request(method, url, **httplib_request_kw) File “/usr/local/lib/python3.5/http/client.py”, line 1107, in request self._send_request(method, url, body, headers) File “/usr/local/lib/python3.5/http/client.py”, line 1152, in _send_request self.endheaders(body) File “/usr/local/lib/python3.5/http/client.py”, line 1103, in endheaders self._send_output(message_body) File “/usr/local/lib/python3.5/http/client.py”, line 934, in _send_output self.send(msg) File “/usr/local/lib/python3.5/http/client.py”, line 877, in send self.connect() File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 166, in connect conn = self._new_conn() File “/usr/local/lib/python3.5/site-packages/urllib3/connection.py”, line 150, in _new_conn self, “Failed to establish a new connection: %s” % e) urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f086504f2b0>: Failed to establish a new connection: [Errno 111] Connection refused False
Issue Analytics
- State:
- Created 6 years ago
- Comments:18 (6 by maintainers)
Top GitHub Comments
You have 2 containers on the same network.
Are you using Docker-compose?
Localhost is probably the wrong hostname to use.
When Docker networks containers you can communicate between containers by using the name of the containers.
So say you named your elasticsearch container
elasticsearch
you would then want to establish a connection to ES using the nameelasticsearch
instead of localhost.By using
localhost
the container running -dsl-py will attempt to connect to WS running within the same container. But it will fail cause ES is available in a different container.The reason I asked about compose is because it makes it easy to name your services and the name of each service also doubles as a DNS name to reach said service.
@davidefiocco @mihaitodor
ahh yes that would make sense.
Another option in your indexer script is to put the
sleep
in a while loop:edit: or even better: https://github.com/elastic/elasticsearch-py/blob/master/elasticsearch/helpers/test.py#L22-L28