我正在尝试让 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 而失败。
这确实感觉像是我系统上的核心配置问题,但我不知道问题出在哪里。