Types

This outline covers the types used in the docker-py client.

Docker API Client

The docker-py client exposes a high-level API that simplifies interactions with the Docker daemon. It provides various methods and classes for managing containers, images, volumes, networks, and more.

Connection Types

The docker-py client allows for connecting to the Docker daemon using various connection types:

  • Unix Socket: This is the default and recommended connection type when the Docker daemon is running on the same host. docker/client.py
  • TCP Socket: When the Docker daemon is running on a remote host, you can connect using a TCP socket. docker/client.py
  • SSH: Allows connecting to a remote Docker daemon through an SSH tunnel. docker/client.py

Connection Examples

  1. Unix Socket:
import docker
          
          client = docker.from_env()
          
  1. TCP Socket:
import docker
          
          client = docker.DockerClient(base_url='tcp://192.168.99.100:2376')
          
  1. SSH:
import docker
          
          client = docker.DockerClient(base_url='ssh://user@host:port')
          

Authentication

The docker-py client supports different authentication mechanisms:

  • Docker Credentials: Docker credentials are used to authenticate with the Docker daemon. docker/auth.py
  • Environment Variables: Docker credentials can be stored in environment variables such as DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH, and DOCKER_USER. docker/auth.py

Authentication Examples

  1. Using Docker Credentials:
import docker
          
          client = docker.from_env()
          
  1. Using Environment Variables:
import docker
          
          client = docker.DockerClient(base_url='tcp://192.168.99.100:2376', tls=True, tls_verify=True, tls_ca_cert='ca.pem', tls_client_cert='client.pem', tls_client_key='client.key')
          

Docker API Endpoints

The docker-py client provides wrappers for various Docker API endpoints. docker/api.py

Docker API Objects

The docker-py client defines objects that represent Docker entities such as containers, images, volumes, and networks. These objects provide methods for interacting with these entities. docker/models.py