-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
The following working code example:
from docker.client import Client
from docker.utils import kwargs_from_env
cli = Client(**kwargs_from_env())
print kwargs_from_env()
name_one = 'exec_container'
cli.create_container(**{'name': name_one, 'image': 'golang'})
cli.start(name_one)
cli.logs(name_one, stdout=True, stderr=True) # commenting this line out allows the below to execute perfectly
e = cli.exec_create(container=name_one, cmd='ls /usr/local/bin')
print cli.exec_start(exec_id=e['Id'])
Produces the following output, when run inside a docker-machine on Mac configuration:
{'tls': <docker.tls.TLSConfig object at 0x101156a50>, 'base_url': 'docker.dev:2376'}
Traceback (most recent call last):
File "/Users/aldenpeterson/go/projects/src/github.com/Workiva/Nastypath/src/python/mcve.py", line 21, in <module>
print cli.exec_start(exec_id=e['Id'])
File "/Library/Python/2.7/site-packages/docker/utils/decorators.py", line 35, in wrapper
return f(self, *args, **kwargs)
File "/Library/Python/2.7/site-packages/docker/api/exec_api.py", line 75, in exec_start
return self._get_result_tty(stream, res, tty)
File "/Library/Python/2.7/site-packages/docker/client.py", line 311, in _get_result_tty
self._raise_for_status(res)
File "/Library/Python/2.7/site-packages/docker/client.py", line 146, in _raise_for_status
raise errors.APIError(e, response, explanation=explanation)
docker.errors.APIError: 500 Server Error: Internal Server Error ("http: Hijack is incompatible with use of CloseNotifier")
I should note that this works with containers that persist runtime and/or exit immediately. If you prefer to substitute another image that should reproduce the error.
It seems that when you run Client.logs()
it prevents future Client.exec_start
from working. Note that running Client.logs()
on any running container will also cause this, not just the same container.
This error is rather difficult to trace down as all you see is the above obscure error (which is a Golang bug coming through Docker itself, apparently. This was fixed at some point recently - both the Golang repository and the Docker one show it as fixed, so I am not sure where the root of the bug is currently).
This does not seem to have the problem when not using docker-machine although I cannot easily verify this myself.
Here are my system details:
pip freeze | grep docker-py && python --version && docker version
You are using pip version 8.0.2, however version 8.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
docker-py==1.7.2
Python 2.7.11
Client:
Client:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Thu Mar 10 21:49:11 2016
OS/Arch: darwin/amd64
Server:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Thu Mar 10 21:49:11 2016
OS/Arch: linux/amd64
docker-machine --version
docker-machine
version 0.6.0, build e27fb87