Book Image

Docker Cookbook

By : Neependra Khare
Book Image

Docker Cookbook

By: Neependra Khare

Overview of this book

<p>Docker is a Linux container engine that allows you to create consistent, stable, and production-quality environments with containers.</p> <p>You will start by installing Docker and understanding and working with containers and images. You then proceed to learn about network and data management for containers. The book explores the RESTful APIs provided by Docker to perform different actions such as image/container operations. Finally, the book explores logs and troubleshooting Docker to solve issues and bottlenecks. This book will also help you understand Docker use cases, orchestration, security, ecosystems, and hosting platforms to make your applications easy to deploy, build, and collaborate on.</p>
Table of Contents (17 chapters)
Docker Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Exploring Docker remote API client libraries


In the last few recipes, we explored the APIs provided by Docker to connect and perform operations to the remote Docker daemon. The Docker community has added bindings for different programming languages to access those APIs. Some of them are listed at https://docs.docker.com/reference/api/remote_api_client_libraries/.

Note that Docker Maintainers do not maintain these libraries. Let's explore Python bindings with a few examples and see how it uses the Docker remote API.

Getting ready

  • Install docker-py on Fedora:

    $ sudo yum install python-docker-py
    

    Alternatively, use pip to install the package:

    $ sudo pip install docker-py
    
  • Import the module:

    $ python
    >>> import docker
    

How to do it…

  1. Create the client, using the following steps:

    1. Connect through the Unix Socket:

      	>>> client = docker.Client(base_url='unix://var/run/docker.sock', version='1.18',  timeout=10) 
      
    2. Connect over HTTP:

      	>>> client = docker.Client(base_url='http://dockerhost...