Docker-py: Max retries exceeded with url

Created on 16 Aug 2014  路  11Comments  路  Source: docker/docker-py

Hi,
when I'm trying to get information from the docker host just like this:

c= docker.Client(base_url='http://10.82.81.165:1414',version='1.10',timeout=20)
c.images()

I got the mistake:
File "/home/wangzhe/workspace/testDjango/testDjango/init.py", line 7, in
c.images()
File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 515, in images
res = self._result(self._get(self._url("/images/json"), params=params),
File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 74, in _get
return self.get(url, *_self._set_request_timeout(kwargs))
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 468, in get
return self.request('GET', url, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 456, in request
resp = self.send(prep, *_send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 559, in send
r = adapter.send(request, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 375, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.82.81.165', port=1414): Max retries exceeded with url: /v1.10/images/json?only_ids=0&all=0 (Caused by : [Errno 111] Connection refused)
Could anyone give me some suggestions?
Thank you!

statuinvalid

All 11 comments

It's likely that you're connecting to the wrong IP/port, or you're behind a firewall of some sort. Check your setup to make sure that's not the case!

Thanks for your suggestion!
My docker deamon didn's listen to the right ports,I was already fixed that problem.

I get a similar error when I try to connect to docker daemon after using the remove_container method. My output is:

127.0.0.1 - - [04/Jul/2016 13:07:25] "GET /docker/images?cmd=get-records&limit=100&offset=0&sort[0][field]=RepoTags&sort[0][direction]=asc HTTP/1.1" 500 -
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2000, in call
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1991, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1567, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functionsrule.endpoint
File "/home/anselal/docker-isthmos/app/views.py", line 21, in docker_images
images = client.images()
File "/usr/local/lib/python2.7/dist-packages/docker/api/image.py", line 39, in images
res = self._result(self._get(self._url("/images/json"), params=params),
File "/usr/local/lib/python2.7/dist-packages/docker/utils/decorators.py", line 47, in inner
return f(self, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 120, in _get
return self.get(url, *_self._set_request_timeout(kwargs))
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 487, in get
return self.request('GET', url, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 475, in request
resp = self.send(prep, *_send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 585, in send
r = adapter.send(request, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 467, in send
raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=2375): Max retries exceeded with url: /v1.22/images/json?only_ids=0&all=0 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))

@anselal you're connecting to docker engine running on 127.0.0.1:2375 but your flask app is not able to connect. Can you verify that engine is running on the port and accepting connections? This can be easily done with curl:

$ curl -v 127.0.0.1:2375/info

I am actually using unix socket to connect to docker. I do not understand why it tries to reconnect to the daemon with tcp.

This is the code of docker-py which results into failure:

File "/home/anselal/docker-isthmos/app/views.py", line 21, in docker_images
  images = client.images()

How's the client being initiated?

from docker import Client
client = Client(base_url='unix://var/run/docker.sock')

But the exception mentions localhost, not unix socket. Looks like the app either
a) changes the base_url of client instance
b) initiates client multiple times

Anyway, this is certainly not an issue of docker-py.

Well, ok. I will try to debug it. Thanks anyways

Hi! I've the same error :
1:

My Post

def dni(request):

url = "http://127.0.0.1:9200/api/check-api/"
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"email\"\r\n\r\[email protected]\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\n1234\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n{\n\"numeroDossier\": \"GU-CE-GN00000204\",\n\"numeroIdentificationFiscale\": \"031246\",\n\"dateImmatriculation\":\"2018-04-06\",\n\"numeroFormulaire\":\"0124/MB/DNI/CI/2018\",\n\"nomFichierEnvoye\":\"nif_GU-CE-GN00000204.pdf\",\n\"nomPrepose\":\"KEITA\",\nprenomPrepose\":\"SALIF\"\n}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"

playload = {
    "Content-Disposition": "form-data",  
    "email": "[email protected]",
    "password": password,
    "file": {
        "numeroDossier": "GU-CE-GN00000204",
        "numeroIdentificationFiscale": "031246",
        "dateImmatriculation":"2018-04-06",
        "numeroFormulaire":"0124/MB/DNI/CI/2018",
        "nomFichierEnvoye":"nif_GU-CE-GN00000204.pdf",
        "nomPrepose":"KEITA",
        "prenomPrepose":"SALIF"
    }
}
headers = {
    'content-type': "multipart/form-data",
    'Content-Type': "application/x-www-form-urlencoded",
    'Cache-Control': "no-cache"
}
if request.method == 'POST':
    response = requests.request("POST", url, data=payload, headers=headers)
    messages.success(request, _('Json envoy茅 avec succes!'))
return render(request, 'example.html')

2 :

error

django_1 | raise ConnectionError(e, request=request)
django_1 | requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=9200): Max retries exceeded with url: /api/check-api/ (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))
django_1 | [30/May/2018 09:42:22] "POST /contribuable/example-api HTTP/1.1" 500 191335

Could anyone HELP ME please!

Did you ever resolve this? I have the same problem and I am fairly new to Docker as well. I'm running ubuntu on hyper-v with docker and the ExposeVirtualizationExtensions set to true. And it seems to work for the most part.
Powershell: Hyper-V Configuration command for Exposing Virtualization to the VM.
"Set-VMProcessor "Ubuntu 18.04.1 LTS" -ExposeVirtualizationExtensions $true"

To me, this looks like an issue with port or routing issue. When I run curl I get Connection refused on the port.
curl -v 127.0.0.1:2376

  • Rebuilt URL to: 127.0.0.1:2376/
  • Trying 127.0.0.1...
  • TCP_NODELAY set
  • connect to 127.0.0.1 port 2376 failed: Connection refused
  • Failed to connect to 127.0.0.1 port 2376: Connection refused
  • Closing connection 0
    curl: (7) Failed to connect to 127.0.0.1 port 2376: Connection refused
Was this page helpful?
0 / 5 - 0 ratings