来自docker-py客户端的意外行为

时间:2016-12-18 19:25:58

标签: python dockerpy

我试图从入门文档(https://docker-py.readthedocs.io/en/stable/index.html#getting-started)中为docker-py包运行一些基本代码,但是在Python 2.7.6和Python 3.4.3中都遇到了问题:

>>> client = docker.from_env()
>>> client.images.list()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'list'

奇怪的是,我可以看到一个图像列表:

client.images()
[{u'Created': 1476822682, u'Labels': None, u'VirtualSize': 4802964, u'ParentId': u'', u'RepoTags': [u'alpine:3.4'], u'RepoDigests': [u'alpine@sha256:1354db23ff5478120c980eca1611a51c9f2b88b61f24283ee8200bf9a54f2e5c'], u'Id': u'sha256:baa5d63471ead618ff91ddfacf1e2c81bf0612bfeb1daf00eb0843a41fbfade3', u'Size': 4802964}]

根据文档,这似乎是出乎意料的行为。为什么client.images是一个列表而不是Images类的实例(如下所示:https://docker-py.readthedocs.io/en/stable/images.html),正如文档似乎提示的那样?我一定很遗憾。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

想出来。我有pip安装了docker-py,但是当前版本的软件包在pypi上简称为“docker”。