question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New ConnectionError [Errno 111] Connection Refused using Docker

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

48reactions
fxdgearcommented, Jan 22, 2018

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 name elasticsearch 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.

9reactions
fxdgearcommented, Feb 12, 2018

@davidefiocco @mihaitodor

ahh yes that would make sense.

Another option in your indexer script is to put the sleep in a while loop:

import time
connected = False

while not connected:
    try:
        es.info()
        connected = True
    except ConnectionError:
        print("Elasticsearch not available yet, trying again in 2s...)
        time.sleep(2)

edit: or even better: https://github.com/elastic/elasticsearch-py/blob/master/elasticsearch/helpers/test.py#L22-L28

Read more comments on GitHub >

github_iconTop Results From Across the Web

Docker. Failed to establish a new connection: [Errno 111 ...
Im trying to run it just on localhost. When i use docker-compose up, everything is ok, until im trying send request. app 1...
Read more >
HELP!... ConnectionRefusedError: [Errno:111] Connection ...
when in Command Prompt and I try to run 'docker-compose up' Docker-compose starts up, but gets interrupted with the following message:
Read more >
ConnectionRefusedError: [Errno 111] Connection refused
Hello,. I'm using PyODM library for creating orthophotos,. for that I have created flask application. in wich my function looks like this:-
Read more >
Docker. Failed to establish a new connection ... - iTecNote
Failed to establish a new connection: [Errno 111] Connection refused' I want to send post request from one container to another, both are...
Read more >
HTTP connection refused errors - Google Groups
I am running AWX using Docker on a Cent OS 7 host. ... object at 0x18f56d0>: Failed to establish a new connection: [Errno...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found