`client.containers.run()` doesn't exist
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
Hi there,
Today I decided to look into docker-py for a project I will be working on in the coming months. After a fresh install of docker and docker-py today, I must say that, somehow, docker-py doesn't quite work.
The getting started examples show this code:
>>> import docker
>>> client = docker.from_env()
>>> client.containers.run("ubuntu", "echo hello world")
'hello world\n'
But when I run this, I see
In [1]: import docker
In [2]: client = docker.from_env()
In [3]: client.containers.run("ubuntu", "echo hello world")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-5336699d83c5> in <module>
----> 1 client.containers.run()
AttributeError: 'function' object has no attribute 'run'
I also tried to manually create an instance of the docker.Client as detailed in the docs
In [1]: import docker
# Note: The following line from the docs fails to execute... :-(
In [2]: client = docker.DockerClient(base_url='unix://var/run/docker.sock')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-a0131c4bce50> in <module>
----> 1 client = docker.DockerClient(base_url='unix://var/run/docker.sock')
AttributeError: module 'docker' has no attribute 'DockerClient'
In [3]: client = docker.Client(base_url='unix://var/run/docker.sock')
In [4]: client.containers.run("hello-world")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-a00eac6bdc71> in <module>
----> 1 client.containers.run("hello-world")
AttributeError: 'function' object has no attribute 'run'
Calling docker through the CLI works as expected
$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
[ ... ]
Note that I am a member of the docker group on my system. I already tried to reboot my system but to no avail.
Here's some info on my system:
$ docker --version
Docker version 19.03.11, build 42e35e61f3
$ pip3 show docker
Name: docker
Version: 4.2.1
Summary: A Python library for the Docker Engine API.
Home-page: https://github.com/docker/docker-py
Author: None
Author-email: None
License: Apache License 2.0
Location: /home/<user>/.local/lib/python3.7/site-packages
Requires: websocket-client, six, requests
Required-by:
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
I'd be grateful for any help and/or pointers to a possible cause...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the getting-started example using docker.from_env() and client.containers.run(), then compare it with the client reference and the reported docker 4.2.1 installation. Reproduce the AttributeError and determine whether the library behavior or the linked documentation is inconsistent; done means the documented client usage works or the documentation accurately reflects the supported API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100