2
這看似簡單,但我想用Dockerpy複製下面的泊塢窗命令:Dockerpy執行命令貓日誌文件
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")
我真的不知道WH在我做的不正確或需要爲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
這看起來像[這些](https://github.com/docker/compose/issues/1275)[bug](https://github.com/golang/go/issues/9763)應該有已修復。你使用的是什麼版本的Docker? – morxa
@morxa補充說,不敢相信我忘了補充一點! – enderland
@JimB錯誤來自Docker本身的Go源代碼。我不確定是否更改Go的版本可以解決問題(請參閱[Go github中的這個錯誤](https://github.com/golang/go/issues/9763))。 – enderland