Fix images low-level documentation examples

I realize that the documentation of low-level `images` was outdated when
answering issue #2798

The issue can reproduce it with a simple test:

```py
In [1]: import docker
In [2]: client = docker.from_env()
In [3]: client.pull
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-d0931943ca5d> in <module>
----> 1 client.pull

~/docker-py/docker/client.py in __getattr__(self, name)
    219                      "object APIClient. See the low-level API section of the "
    220                      "documentation for more details.")
--> 221         raise AttributeError(' '.join(s))
    222
    223

AttributeError: 'DockerClient' object has no attribute 'pull' In Docker SDK for Python 2.0, this method is now on the object APIClient. See the low-level API section of the documentation for more details.

In [4]: client.push
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-f7d5b860a184> in <module>
----> 1 client.push

~/docker-py/docker/client.py in __getattr__(self, name)
    219                      "object APIClient. See the low-level API section of the "
    220                      "documentation for more details.")
--> 221         raise AttributeError(' '.join(s))
    222
    223

AttributeError: 'DockerClient' object has no attribute 'push' In Docker SDK for Python 2.0, this method is now on the object APIClient. See the low-level API section of the documentation for more details.

In [5]: client.tag
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-043bdfd088ca> in <module>
----> 1 client.tag

~/docker-py/docker/client.py in __getattr__(self, name)
    219                      "object APIClient. See the low-level API section of the "
    220                      "documentation for more details.")
--> 221         raise AttributeError(' '.join(s))
    222
    223

AttributeError: 'DockerClient' object has no attribute 'tag' In Docker SDK for Python 2.0, this method is now on the object APIClient. See the low-level API section of the documentation for more details.

In [6]: client.get_image
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-477c12713276> in <module>
----> 1 client.get_image

~/docker-py/docker/client.py in __getattr__(self, name)
    219                      "object APIClient. See the low-level API section of the "
    220                      "documentation for more details.")
--> 221         raise AttributeError(' '.join(s))
    222
    223

AttributeError: 'DockerClient' object has no attribute 'get_image' In Docker SDK for Python 2.0, this method is now on the object APIClient. See the low-level API section of the documentation for more details.

In [7]: client.api.get_image
Out[7]: <bound method ImageApiMixin.get_image of <docker.api.client.APIClient object at 0x7fad6a2037c0>>

In [8]: client.api.tag
Out[8]: <bound method ImageApiMixin.tag of <docker.api.client.APIClient object at 0x7fad6a2037c0>>

In [9]: client.api.pull
Out[9]: <bound method ImageApiMixin.pull of <docker.api.client.APIClient object at 0x7fad6a2037c0>>

In [10]: client.api.push
Out[10]: <bound method ImageApiMixin.push of <docker.api.client.APIClient object at 0x7fad6a2037c0>>
```

Signed-off-by: Felipe Ruhland <felipe.ruhland@gmail.com>
1 file changed
tree: 5dc821e62f4f7c4a4a510bd13bcc5719f3ce9ed7
  1. .github/
  2. docker/
  3. docs/
  4. scripts/
  5. tests/
  6. .coveragerc
  7. .dockerignore
  8. .editorconfig
  9. .gitignore
  10. .readthedocs.yml
  11. appveyor.yml
  12. CONTRIBUTING.md
  13. Dockerfile
  14. Dockerfile-docs
  15. docs-requirements.txt
  16. Jenkinsfile
  17. LICENSE
  18. MAINTAINERS
  19. Makefile
  20. MANIFEST.in
  21. pytest.ini
  22. README.md
  23. requirements.txt
  24. setup.cfg
  25. setup.py
  26. test-requirements.txt
  27. tox.ini
README.md

Docker SDK for Python

Build Status

A Python library for the Docker Engine API. It lets you do anything the docker command does, but from within Python apps – run containers, manage containers, manage Swarms, etc.

Installation

The latest stable version is available on PyPI. Either add docker to your requirements.txt file or install with pip:

pip install docker

If you are intending to connect to a docker host via TLS, add docker[tls] to your requirements instead, or install with pip:

pip install docker[tls]

Usage

Connect to Docker using the default socket or the configuration in your environment:

import docker
client = docker.from_env()

You can run containers:

>>> client.containers.run("ubuntu:latest", "echo hello world")
'hello world\n'

You can run containers in the background:

>>> client.containers.run("bfirsh/reticulate-splines", detach=True)
<Container '45e6d2de7c54'>

You can manage containers:

>>> client.containers.list()
[<Container '45e6d2de7c54'>, <Container 'db18e4f20eaa'>, ...]

>>> container = client.containers.get('45e6d2de7c54')

>>> container.attrs['Config']['Image']
"bfirsh/reticulate-splines"

>>> container.logs()
"Reticulating spline 1...\n"

>>> container.stop()

You can stream logs:

>>> for line in container.logs(stream=True):
...   print(line.strip())
Reticulating spline 2...
Reticulating spline 3...
...

You can manage images:

>>> client.images.pull('nginx')
<Image 'nginx'>

>>> client.images.list()
[<Image 'ubuntu'>, <Image 'nginx'>, ...]

Read the full documentation to see everything you can do.