Getting error 'ConnectionError: ('Connection aborted.', error(2, 'No such file or directory'))'
I am getting an error when trying to use dockerpty. Using the example in the README:
import docker
import dockerpty
client = docker.Client()
container = client.create_container(
'busybox:latest',
stdin_open=True,
tty=True,
command='/bin/sh')
dockerpty.start(client, container)
When I run this, I get the error:
Traceback (most recent call last):
File "test_script.py", line 9, in <module>
command='/bin/sh')
File "/Users/michaelbarton/Library/Python/2.7/lib/python/site-packages/docker/api/container.py", line 116, in create_container
return self.create_container_from_config(config, name)
File "/Users/michaelbarton/Library/Python/2.7/lib/python/site-packages/docker/api/container.py", line 126, in create_container_from_config
res = self._post_json(u, data=config, params=params)
File "/Users/michaelbarton/Library/Python/2.7/lib/python/site-packages/docker/client.py", line 166, in _post_json
return self._post(url, data=json.dumps(data2), **kwargs)
File "/Users/michaelbarton/Library/Python/2.7/lib/python/site-packages/docker/client.py", line 107, in _post
return self.post(url, **self._set_request_timeout(kwargs))
File "/Users/michaelbarton/Library/Python/2.7/lib/python/site-packages/requests/sessions.py", line 508, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/Users/michaelbarton/Library/Python/2.7/lib/python/site-packages/requests/sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "/Users/michaelbarton/Library/Python/2.7/lib/python/site-packages/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/Users/michaelbarton/Library/Python/2.7/lib/python/site-packages/requests/adapters.py", line 415, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(2, 'No such file or directory'))
Here are the details of my docker install, using docker-machine:
Client:
Version: 1.9.0
API version: 1.21
Go version: go1.4.3
Git commit: 76d6bc9
Built: Tue Nov 3 19:20:09 UTC 2015
OS/Arch: darwin/amd64
Server:
Version: 1.9.0
API version: 1.21
Go version: go1.4.3
Git commit: 76d6bc9
Built: Tue Nov 3 19:20:09 UTC 2015
OS/Arch: linux/amd64
And the details of my OS:
Darwin Michaels-MacBook-Air.local 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64 i386 MacBookAir7,2 Darwin
The following command does however work:
docker run -ti busybox:latest /bin/sh
I have tried the above script on a separate work computer and got a similar error. This was with docker-py-1.5.0 and dockerpty-0.3.4
For anyone else coming across this: you get this error if there are no docker machines running. Try eval ${docker-machine env default} (or swap default for your machine name)
@michaelbarton @mejamiewilson Did you find any solution ? I understand that eval ${docker-machine env default} works great for command, but any solution for Client() via script ?
OS info: Darwin Ravis-MacBook-Pro.local 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
If you're using Docker Machine, you can point docker-py at it using docker-machine env and the kwargs_from_env() utility method.
from docker import Client
from docker.utils import kwargs_from_env
client = Client(**kwargs_from_env(assert_hostname=False))
...
$ eval "$(docker-machine env default)"
$ python script.py