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
python3is installed. ubuntu 16.04might not havepip3, so installpip3using the following command:
$ sudo apt-get -y install python3-pipHow to do it...
- Let's begin by installing the docker package for
pythonusingpip3:
$ sudo pip3 install docker- Now, let's launch
python3and import thedockerandjsonpackages, as demonstrated in the following:

- Having imported the
dockerandjsonpackages, 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...