class documentation

A low-level client for the Docker Engine API. Example: >>> import docker >>> client = docker.APIClient(base_url='unix://var/run/docker.sock') >>> client.version() {u'ApiVersion': u'1.33', u'Arch': u'amd64', u'BuildTime': u'2017-11-19T18:46:37.000000000+00:00', u'GitCommit': u'f4ffd2511c', u'GoVersion': u'go1.9.2', u'KernelVersion': u'4.14.3-1-ARCH', u'MinAPIVersion': u'1.12', u'Os': u'linux', u'Version': u'17.10.0-ce'} Args: base_url (str): URL to the Docker server. For example, ``unix:///var/run/docker.sock`` or ``tcp://127.0.0.1:1234``. version (str): The version of the API to use. Set to ``auto`` to automatically detect the server's version. Default: ``1.35`` timeout (int): Default timeout for API calls, in seconds. tls (bool or :py:class:`~docker.tls.TLSConfig`): Enable TLS. Pass ``True`` to enable it with default options, or pass a :py:class:`~docker.tls.TLSConfig` object to use custom configuration. user_agent (str): Set a custom user agent for requests to the server. credstore_env (dict): Override environment variables when calling the credential store process. use_ssh_client (bool): If set to `True`, an ssh connection is made via shelling out to the ssh client. Ensure the ssh client is installed and configured on the host. max_pool_size (int): The maximum number of connections to save in the pool.

Method __init__ Undocumented
Method get_adapter Undocumented
Method reload_config Force a reload of the auth configuration
Class Variable __attrs__ Undocumented
Instance Variable base_url Undocumented
Instance Variable credstore_env Undocumented
Instance Variable timeout Undocumented
Property api_version Undocumented
Method _attach_params Undocumented
Method _attach_websocket Undocumented
Method _check_is_tty Undocumented
Method _create_websocket_connection Undocumented
Method _delete Undocumented
Method _disable_socket_timeout Depending on the combination of python version and whether we're connecting over http or https, we might need to access _sock, which may or may not exist; or we may need to just settimeout on socket itself, which also may or may not have settimeout on it...
Method _get Undocumented
Method _get_raw_response_socket Undocumented
Method _get_result Undocumented
Method _get_result_tty Undocumented
Method _multiplexed_buffer_helper A generator of multiplexed data blocks read from a buffered response.
Method _multiplexed_response_stream_helper A generator of multiplexed data blocks coming from a response stream.
Method _post Undocumented
Method _post_json Undocumented
Method _put Undocumented
Method _raise_for_status Raises stored :class:`APIError`, if one occurred.
Method _read_from_socket Undocumented
Method _result Undocumented
Method _retrieve_server_version Undocumented
Method _set_request_timeout Prepare the kwargs for an HTTP request by inserting the timeout parameter, if not already present.
Method _stream_helper Generator for data coming from a chunked-encoded HTTP response.
Method _stream_raw_result Stream result for TTY-enabled container and raw binary data
Method _unmount Undocumented
Method _url Undocumented
Instance Variable _auth_configs Undocumented
Instance Variable _custom_adapter Undocumented
Instance Variable _general_configs Undocumented
Instance Variable _proxy_configs Undocumented
Instance Variable _version Undocumented

Inherited from BuildApiMixin:

Method build Similar to the ``docker build`` command. Either ``path`` or ``fileobj`` needs to be set. ``path`` can be a local path (to a directory containing a Dockerfile) or a remote URL. ``fileobj`` must be a readable file-like object to a Dockerfile.
Method prune_builds Delete the builder cache
Method _set_auth_headers Undocumented

Inherited from ConfigApiMixin (via BuildApiMixin):

Method configs List configs
Method create_config Create a config
Method inspect_config Retrieve config metadata
Method remove_config Remove a config

Inherited from ContainerApiMixin (via BuildApiMixin, ConfigApiMixin):

Method attach Attach to a container.
Method attach_socket Like ``attach``, but returns the underlying socket-like object for the HTTP request.
Method commit Commit a container to an image. Similar to the ``docker commit`` command.
Method containers List containers. Similar to the ``docker ps`` command.
Method create_container Creates a container. Parameters are similar to those for the ``docker run`` command except it doesn't support the attach options (``-a``).
Method create_container_config Undocumented
Method create_container_from_config Undocumented
Method create_endpoint_config Create an endpoint config dictionary to be used with :py:meth:`create_networking_config`.
Method create_host_config Create a dictionary for the ``host_config`` argument to :py:meth:`create_container`.
Method create_networking_config Create a networking config dictionary to be used as the ``networking_config`` parameter in :py:meth:`create_container`.
Method diff Inspect changes on a container's filesystem.
Method export Export the contents of a filesystem as a tar archive.
Method get_archive Retrieve a file or folder from a container in the form of a tar archive.
Method inspect_container Identical to the `docker inspect` command, but only for containers.
Method kill Kill a container or send a signal to a container.
Method logs Get logs from a container. Similar to the ``docker logs`` command.
Method pause Pauses all processes within a container.
Method port Lookup the public-facing port that is NAT-ed to ``private_port``. Identical to the ``docker port`` command.
Method prune_containers Delete stopped containers
Method put_archive Insert a file or folder in an existing container using a tar archive as source.
Method remove_container Remove a container. Similar to the ``docker rm`` command.
Method rename Rename a container. Similar to the ``docker rename`` command.
Method resize Resize the tty session.
Method restart Restart a container. Similar to the ``docker restart`` command.
Method start Start a container. Similar to the ``docker start`` command, but doesn't support attach options.
Method stats Stream statistics for a specific container. Similar to the ``docker stats`` command.
Method stop Stops a container. Similar to the ``docker stop`` command.
Method top Display the running processes of a container.
Method unpause Unpause all processes within a container.
Method update_container Update resource configs of one or more containers.
Method wait Block until a container stops, then return its exit code. Similar to the ``docker wait`` command.

Inherited from DaemonApiMixin (via BuildApiMixin, ConfigApiMixin, ContainerApiMixin):

Method df Get data usage information.
Method events Get real-time events from the server. Similar to the ``docker events`` command.
Method info Display system-wide information. Identical to the ``docker info`` command.
Method login Authenticate with a registry. Similar to the ``docker login`` command.
Method ping Checks the server is responsive. An exception will be raised if it isn't responding.
Method version Returns version information from the server. Similar to the ``docker version`` command.

Inherited from ExecApiMixin (via BuildApiMixin, ConfigApiMixin, ContainerApiMixin, DaemonApiMixin):

Method exec_create Sets up an exec instance in a running container.
Method exec_inspect Return low-level information about an exec command.
Method exec_resize Resize the tty session used by the specified exec command.
Method exec_start Start a previously set up exec instance.

Inherited from ImageApiMixin (via BuildApiMixin, ConfigApiMixin, ContainerApiMixin, DaemonApiMixin, ExecApiMixin):

Method get_image Get a tarball of an image. Similar to the ``docker save`` command.
Method history Show the history of an image.
Method images List images. Similar to the ``docker images`` command.
Method import_image Import an image. Similar to the ``docker import`` command.
Method import_image_from_data Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but allows importing in-memory bytes data.
Method import_image_from_file Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but only supports importing from a tar file on disk.
Method import_image_from_image Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but only supports importing from another image, like the ``FROM`` Dockerfile parameter.
Method import_image_from_stream Undocumented
Method import_image_from_url Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but only supports importing from a URL.
Method inspect_distribution Get image digest and platform information by contacting the registry.
Method inspect_image Get detailed information about an image. Similar to the ``docker inspect`` command, but only for images.
Method load_image Load an image that was previously saved using :py:meth:`~docker.api.image.ImageApiMixin.get_image` (or ``docker save``). Similar to ``docker load``.
Method prune_images Delete unused images
Method pull Pulls an image. Similar to the ``docker pull`` command.
Method push Push an image or a repository to the registry. Similar to the ``docker push`` command.
Method remove_image Remove an image. Similar to the ``docker rmi`` command.
Method search Search for images on Docker Hub. Similar to the ``docker search`` command.
Method tag Tag an image into a repository. Similar to the ``docker tag`` command.

Inherited from NetworkApiMixin (via BuildApiMixin, ConfigApiMixin, ContainerApiMixin, DaemonApiMixin, ExecApiMixin, ImageApiMixin):

Method connect_container_to_network Connect a container to a network.
Method create_network Create a network. Similar to the ``docker network create``.
Method disconnect_container_from_network Disconnect a container from a network.
Method inspect_network Get detailed information about a network.
Method networks List networks. Similar to the ``docker network ls`` command.
Method prune_networks Delete unused networks
Method remove_network Remove a network. Similar to the ``docker network rm`` command.

Inherited from PluginApiMixin (via BuildApiMixin, ConfigApiMixin, ContainerApiMixin, DaemonApiMixin, ExecApiMixin, ImageApiMixin, NetworkApiMixin):

Method configure_plugin Configure a plugin.
Method create_plugin Create a new plugin.
Method disable_plugin Disable an installed plugin.
Method enable_plugin Enable an installed plugin.
Method inspect_plugin Retrieve plugin metadata.
Method plugin_privileges Retrieve list of privileges to be granted to a plugin.
Method plugins Retrieve a list of installed plugins.
Method pull_plugin Pull and install a plugin. After the plugin is installed, it can be enabled using :py:meth:`~enable_plugin`.
Method push_plugin Push a plugin to the registry.
Method remove_plugin Remove an installed plugin.
Method upgrade_plugin Upgrade an installed plugin.

Inherited from SecretApiMixin (via BuildApiMixin, ConfigApiMixin, ContainerApiMixin, DaemonApiMixin, ExecApiMixin, ImageApiMixin, NetworkApiMixin, PluginApiMixin):

Method create_secret Create a secret
Method inspect_secret Retrieve secret metadata
Method remove_secret Remove a secret
Method secrets List secrets

Inherited from ServiceApiMixin (via BuildApiMixin, ConfigApiMixin, ContainerApiMixin, DaemonApiMixin, ExecApiMixin, ImageApiMixin, NetworkApiMixin, PluginApiMixin, SecretApiMixin):

Method create_service Create a service.
Method inspect_service Return information about a service.
Method inspect_task Retrieve information about a task.
Method remove_service Stop and remove a service.
Method service_logs Get log stream for a service. Note: This endpoint works only for services with the ``json-file`` or ``journald`` logging drivers.
Method services List services.
Method tasks Retrieve a list of tasks.
Method update_service Update a service.

Inherited from SwarmApiMixin (via BuildApiMixin, ConfigApiMixin, ContainerApiMixin, DaemonApiMixin, ExecApiMixin, ImageApiMixin, NetworkApiMixin, PluginApiMixin, SecretApiMixin, ServiceApiMixin):

Method create_swarm_spec Create a :py:class:`docker.types.SwarmSpec` instance that can be used as the ``swarm_spec`` argument in :py:meth:`~docker.api.swarm.SwarmApiMixin.init_swarm`.
Method get_unlock_key Get the unlock key for this Swarm manager.
Method init_swarm Initialize a new Swarm using the current connected engine as the first node.
Method inspect_node Retrieve low-level information about a swarm node
Method inspect_swarm Retrieve low-level information about the current swarm.
Method join_swarm Make this Engine join a swarm that has already been created.
Method leave_swarm Leave a swarm.
Method nodes List swarm nodes.
Method remove_node Remove a node from the swarm.
Method unlock_swarm Unlock a locked swarm.
Method update_node Update the node's configuration
Method update_swarm Update the Swarm's configuration

Inherited from VolumeApiMixin (via BuildApiMixin, ConfigApiMixin, ContainerApiMixin, DaemonApiMixin, ExecApiMixin, ImageApiMixin, NetworkApiMixin, PluginApiMixin, SecretApiMixin, ServiceApiMixin, SwarmApiMixin):

Method create_volume Create and register a named volume
Method inspect_volume Retrieve volume info by name.
Method prune_volumes Delete unused volumes
Method remove_volume Remove a volume. Similar to the ``docker volume rm`` command.
Method volumes List volumes currently registered by the docker daemon. Similar to the ``docker volume ls`` command.
def __init__(self, base_url=None, version=None, timeout=DEFAULT_TIMEOUT_SECONDS, tls=False, user_agent=DEFAULT_USER_AGENT, num_pools=None, credstore_env=None, use_ssh_client=False, max_pool_size=DEFAULT_MAX_POOL_SIZE): (source)

Undocumented

def get_adapter(self, url): (source)

Undocumented

def reload_config(self, dockercfg_path=None): (source)

Force a reload of the auth configuration Args: dockercfg_path (str): Use a custom path for the Docker config file (default ``$HOME/.docker/config.json`` if present, otherwise ``$HOME/.dockercfg``) Returns: None

__attrs__ = (source)

Undocumented

base_url: str = (source)

Undocumented

credstore_env = (source)

Undocumented

Undocumented

@property
api_version = (source)

Undocumented

def _attach_params(self, override=None): (source)

Undocumented

@check_resource('container')
def _attach_websocket(self, container, params=None): (source)

Undocumented

@check_resource('container')
def _check_is_tty(self, container): (source)

Undocumented

def _create_websocket_connection(self, url): (source)

Undocumented

@update_headers
def _delete(self, url, **kwargs): (source)

Undocumented

def _disable_socket_timeout(self, socket): (source)

Depending on the combination of python version and whether we're connecting over http or https, we might need to access _sock, which may or may not exist; or we may need to just settimeout on socket itself, which also may or may not have settimeout on it. To avoid missing the correct one, we try both. We also do not want to set the timeout if it is already disabled, as you run the risk of changing a socket that was non-blocking to blocking, for example when using gevent.

@update_headers
def _get(self, url, **kwargs): (source)

Undocumented

def _get_raw_response_socket(self, response): (source)

Undocumented

def _get_result(self, container, stream, res): (source)

Undocumented

def _get_result_tty(self, stream, res, is_tty): (source)

Undocumented

def _multiplexed_buffer_helper(self, response): (source)

A generator of multiplexed data blocks read from a buffered response.

def _multiplexed_response_stream_helper(self, response): (source)

A generator of multiplexed data blocks coming from a response stream.

@update_headers
def _post(self, url, **kwargs): (source)

Undocumented

def _post_json(self, url, data, **kwargs): (source)

Undocumented

@update_headers
def _put(self, url, **kwargs): (source)

Undocumented

def _raise_for_status(self, response): (source)

Raises stored :class:`APIError`, if one occurred.

def _read_from_socket(self, response, stream, tty=True, demux=False): (source)

Undocumented

def _result(self, response, json=False, binary=False): (source)

Undocumented

def _retrieve_server_version(self): (source)

Undocumented

def _set_request_timeout(self, kwargs): (source)

Prepare the kwargs for an HTTP request by inserting the timeout parameter, if not already present.

def _stream_helper(self, response, decode=False): (source)

Generator for data coming from a chunked-encoded HTTP response.

def _stream_raw_result(self, response, chunk_size=1, decode=True): (source)

Stream result for TTY-enabled container and raw binary data

def _unmount(self, *args): (source)

Undocumented

def _url(self, pathfmt, *args, **kwargs): (source)

Undocumented

_custom_adapter = (source)

Undocumented

_general_configs = (source)

Undocumented

_proxy_configs = (source)

Undocumented

_version = (source)

Undocumented