api.client

Module Contents

Classes

APIClient(self,base_url=None,version=None,timeout=DEFAULT_TIMEOUT_SECONDS,tls=False,user_agent=DEFAULT_USER_AGENT,num_pools=DEFAULT_NUM_POOLS,credstore_env=None) A low-level client for the Docker Engine API.
class APIClient(base_url=None, version=None, timeout=DEFAULT_TIMEOUT_SECONDS, tls=False, user_agent=DEFAULT_USER_AGENT, num_pools=DEFAULT_NUM_POOLS, credstore_env=None)

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.30

timeout (int): Default timeout for API calls, in seconds. tls (bool or TLSConfig): Enable TLS. Pass

True to enable it with default options, or pass a 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.
__init__(base_url=None, version=None, timeout=DEFAULT_TIMEOUT_SECONDS, tls=False, user_agent=DEFAULT_USER_AGENT, num_pools=DEFAULT_NUM_POOLS, credstore_env=None)
_retrieve_server_version()
_set_request_timeout(kwargs)

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

_post(url, **kwargs)
_get(url, **kwargs)
_put(url, **kwargs)
_delete(url, **kwargs)
_url(pathfmt, *args, **kwargs)
_raise_for_status(response)

Raises stored APIError, if one occurred.

_result(response, json=False, binary=False)
_post_json(url, data, **kwargs)
_attach_params(override=None)
_attach_websocket(container, params=None)
_create_websocket_connection(url)
_get_raw_response_socket(response)
_stream_helper(response, decode=False)

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

_multiplexed_buffer_helper(response)

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

_multiplexed_response_stream_helper(response)

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

_stream_raw_result(response, chunk_size=1, decode=True)

Stream result for TTY-enabled container and raw binary data

_read_from_socket(response, stream, tty=False)
_disable_socket_timeout(socket)

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.

_check_is_tty(container)
_get_result(container, stream, res)
_get_result_tty(stream, res, is_tty)
_unmount(*args)
get_adapter(url)
api_version()
reload_config(dockercfg_path=None)

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