Exploring Docker remote API client libraries
In the previous recipes, we explored APIs provided by Docker to connect and perform operations on the Docker daemon. Docker also provides the Software Development Kit for the python
and go
languages.
In this recipe, let's explore the python
SDK with a few examples.
Getting ready
- Ensure
python3
is installed. ubuntu 16.04
might not havepip3
, so installpip3
using the following command:
$ sudo apt-get -y install python3-pip
How to do it...
- Let's begin by installing the docker package for
python
usingpip3
:
$ sudo pip3 install docker
- Now, let's launch
python3
and import thedocker
andjson
packages, as demonstrated in the following:

- Having imported the
docker
andjson
packages, let's connect to the Docker daemon through the Unix socket,unix://var/run/docker.sock
, usingdocker.DockerClient
, as shown here:

Here, base_url
is the Docker daemon's connection address.
- Continue on to print the Docker daemon version using the following code:

Here, the client.version...