我试图让docker-py正常工作,并且遇到了一个可能与docker-py无关的基本问题。
我通过pip安装了docker-py(这里是重新运行它的输出 - 应该回答版本问题):
>pip install docker-py
Requirement already satisfied: docker-py in /usr/local/lib/python2.7/site-packages
Requirement already satisfied: docker-pycreds>=0.2.1 in /usr/local/lib/python2.7/site-packages (from docker-py)
Requirement already satisfied: backports.ssl-match-hostname>=3.5; python_version < "3.5" in /usr/local/lib/python2.7/site-packages (from docker-py)
Requirement already satisfied: ipaddress>=1.0.16; python_version < "3.3" in /usr/local/lib/python2.7/site-packages (from docker-py)
Requirement already satisfied: requests!=2.11.0,>=2.5.2 in /usr/local/lib/python2.7/site-packages (from docker-py)
Requirement already satisfied: six>=1.4.0 in /usr/local/lib/python2.7/site-packages (from docker-py)
Requirement already satisfied: websocket-client>=0.32.0 in /usr/local/lib/python2.7/site-packages (from docker-py)
尝试执行一些代码示例(来自http://containertutorials.com/py/docker-py.html)并且正在失败之门:
>python
Python 2.7.13 (default, Dec 17 2016, 23:03:43)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from docker import client
>>> cli = Client(base_url='unix://var/run/docker.sock')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Client' is not defined
尝试使用AutoVersionClient(client = AutoVersionClient(base_url='unix://var/run/docker.sock')
)的不同代码示例时,我遇到了类似的失败,但是由于未定义类似的AutoVersionClient而失败。
这确实感觉就像我系统上的核心配置问题,但我不知道问题出在哪里。
答案 0 :(得分:1)
客户和客户不一样吗?
✗ python
Python 2.7.12 (default, Nov 8 2016, 15:40:43)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from docker import Client
>>> cli = Client(base_url='unix://var/run/docker.sock')
>>> from docker import client
>>>
答案 1 :(得分:0)
如果您已安装docker-py 2.0或更新版本,则客户端已重命名。现在,低级API是docker.APIClient
,而不是docker.Client
。