0

我正在尝试让 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 而失败。

这确实感觉像是我系统上的核心配置问题,但我不知道问题出在哪里。

4

2 回答 2

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
>>>
于 2017-02-09T17:22:48.220 回答
0

如果您安装了 docker-py 2.0 或更高版本,则客户端已重命名。低级 API 现在是docker.APIClient,而不是docker.Client

于 2017-02-16T13:30:54.817 回答