docker-machine swarm集群 如何使用docker-py获取集群信息


大家好,不知道大家是否尝遇到过使用docker-py获取swarm集群状态信息报错的问题,我大概梳理了一下问题,求大家指点.

1.需求:
希望通过docker-py获取swarm(docker-machine方式创建)集群上的集群node个数,node状态,运新container个数等信息

2.准备:
使用本地配置文件(ip:port)方式,创建swarm集群,可以通过以下方式获取集群容器信息
def get_all_containers():
list = []
cli = Client(base_url='tcp://192.168.1.151:2376')
list = cli.containers()
return list
参考:
base_url (str): Refers to the protocol hostname port where the Docker server is hosted.

3.问题描述
使用
$docker-machine create -d generic --generic-ip-address=192.168.1.102 --swarm --swarm-master --swarm-discovery="consul://$(docker-machine ip consul):8500" --engine-opt="cluster-store=consul://$(docker-machine ip consul):8500" --engine-opt="cluster-advertise=eth0:2376" --engine-opt="insecure-registry=192.168.1.151:5000" master
创建swarm集群成功(确认集群创建成功,可以通过dokcer info看到集群信息,这里只截取了swarm-master的创建语句)

在docker-machine和swarm-master上使用2中接口,报错如下:

client = Client(base_url='tcp://192.168.1.102:2376')
client.containers()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/docker/api/container.py", line 69, in containers
res = self._result(self._get(u, params=params), True)
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 112, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 480, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 426, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine('\x15\x03\x01\x00\x02\x02\n',))
未google到相似问题.
4.参考信息
http://docker-py.readthedocs.io/en/stable/api/

$docker version
Client:
Version: 1.11.0
API version: 1.23
Go version: go1.5.4
Git commit: 4dc5990
Built: Wed Apr 13 18:34:23 2016
OS/Arch: linux/amd64

Server:
Version: 1.11.0
API version: 1.23
Go version: go1.5.4
Git commit: 4dc5990
Built: Wed Apr 13 18:34:23 2016
OS/Arch: linux/amd64

swarm version 1.2.2 (34e3da3)

docker-machine version 0.6.0, build e27fb87
已邀请:

要回复问题请先登录注册