0

I'm trying to get docker-py working and am running into a fundamental issue that may not be related to docker-py at all.

I installed docker-py via pip (here's the output of re-running it - should answer version questions):

>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)

Trying to execute some of the code samples (from http://containertutorials.com/py/docker-py.html) and am failing right out the gate:

>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

I get a similar failure trying a different code example that leverages AutoVersionClient (client = AutoVersionClient(base_url='unix://var/run/docker.sock')) but that fails with the similar AutoVersionClient not defined.

This sure feels like a core configuration issue on my system, but I've no idea where the problem lies.

Chris Weiss
  • 157
  • 3
  • 10
  • Adding more to this - I set up a Vagrant with ubuntu/trusty64 (Python 2.7.6), ran the above code and got the same result, so I dont think it's an environment issue. – Chris Weiss Feb 09 '17 at 18:06

2 Answers2

1

Client and client are not the same thing?

✗ 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
>>>
MLindsay
  • 118
  • 3
  • 8
  • Is interesting that it lets me import both though. Never really looked into that. – MLindsay Feb 09 '17 at 17:23
  • I get a different error when the case matches: `TypeError: 'module' object is not callable` – Chris Weiss Feb 09 '17 at 17:46
  • There is a suggestion here that the port is in use, and thats why the socket is unable to be created. https://forums.docker.com/t/automatically-building-containers-and-creating-images/11180/5 Unfortunately, no solution provided in that thread. – MLindsay Feb 09 '17 at 18:32
0

If you've installed docker-py 2.0 or newer, the clients have been renamed. The low-level API is now docker.APIClient, not docker.Client.

Erik
  • 176
  • 1
  • 4
  • Thanks. `pip freeze` says I'm running docker-py==1.10.6. – Chris Weiss Feb 16 '17 at 19:15
  • Yes, MLindsay had the correct answer, I did not look closely enough. The reason you were able to import both is because there is a ``client.py`` in the ``docker`` directory within the [docker-py codebase](https://github.com/docker/docker-py/blob/1.10.6/docker). The ``__init__.py`` [imports the Client class](https://github.com/docker/docker-py/blob/1.10.6/docker/__init__.py#L6) from ``client.py``. Thus, ``docker.client.Client`` and ``docker.Client`` are equivalent. – Erik Feb 17 '17 at 20:04