这看起来很简单,但我正在尝试使用 Docker-py 复制以下 Docker 命令:
docker exec dockerName cat /var/log/foo.log
使用 dockerpy,似乎以下应该工作:
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'])
但是,当我运行它时,我收到以下错误跟踪:
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")
我不确定我做错了什么或需要为 docker-py 做不同的事情。在上面之后我可以立即执行命令行命令。
一切的版本:
docker --version
Docker version 1.10.0, build 590d5108
docker-machine --version
docker-machine version 0.6.0, build e27fb87
pip freeze | grep docker-py
docker-py==1.7.2