class APIClient(requests.Session, BuildApiMixin, ConfigApiMixin, ContainerApiMixin, DaemonApiMixin, ExecApiMixin, ImageApiMixin, NetworkApiMixin, PluginApiMixin, SecretApiMixin, ServiceApiMixin, SwarmApiMixin, VolumeApiMixin): (source)
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 |
Undocumented |
Method | reload |
Force a reload of the auth configuration |
Class Variable | __attrs__ |
Undocumented |
Instance Variable | base |
Undocumented |
Instance Variable | credstore |
Undocumented |
Instance Variable | timeout |
Undocumented |
Property | api |
Undocumented |
Method | _attach |
Undocumented |
Method | _attach |
Undocumented |
Method | _check |
Undocumented |
Method | _create |
Undocumented |
Method | _delete |
Undocumented |
Method | _disable |
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 |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _multiplexed |
A generator of multiplexed data blocks read from a buffered response. |
Method | _multiplexed |
A generator of multiplexed data blocks coming from a response stream. |
Method | _post |
Undocumented |
Method | _post |
Undocumented |
Method | _put |
Undocumented |
Method | _raise |
Raises stored :class:`APIError`, if one occurred. |
Method | _read |
Undocumented |
Method | _result |
Undocumented |
Method | _retrieve |
Undocumented |
Method | _set |
Prepare the kwargs for an HTTP request by inserting the timeout parameter, if not already present. |
Method | _stream |
Generator for data coming from a chunked-encoded HTTP response. |
Method | _stream |
Stream result for TTY-enabled container and raw binary data |
Method | _unmount |
Undocumented |
Method | _url |
Undocumented |
Instance Variable | _auth |
Undocumented |
Instance Variable | _custom |
Undocumented |
Instance Variable | _general |
Undocumented |
Instance Variable | _proxy |
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 |
Delete the builder cache |
Method | _set |
Undocumented |
Inherited from ConfigApiMixin
(via BuildApiMixin
):
Method | configs |
List configs |
Method | create |
Create a config |
Method | inspect |
Retrieve config metadata |
Method | remove |
Remove a config |
Inherited from ContainerApiMixin
(via BuildApiMixin
, ConfigApiMixin
):
Method | attach |
Attach to a container. |
Method | attach |
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 |
Creates a container. Parameters are similar to those for the ``docker run`` command except it doesn't support the attach options (``-a``). |
Method | create |
Undocumented |
Method | create |
Undocumented |
Method | create |
Create an endpoint config dictionary to be used with :py:meth:`create_networking_config`. |
Method | create |
Create a dictionary for the ``host_config`` argument to :py:meth:`create_container`. |
Method | create |
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 |
Retrieve a file or folder from a container in the form of a tar archive. |
Method | inspect |
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 |
Delete stopped containers |
Method | put |
Insert a file or folder in an existing container using a tar archive as source. |
Method | remove |
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 |
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 |
Sets up an exec instance in a running container. |
Method | exec |
Return low-level information about an exec command. |
Method | exec |
Resize the tty session used by the specified exec command. |
Method | exec |
Start a previously set up exec instance. |
Inherited from ImageApiMixin
(via BuildApiMixin
, ConfigApiMixin
, ContainerApiMixin
, DaemonApiMixin
, ExecApiMixin
):
Method | get |
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 |
Import an image. Similar to the ``docker import`` command. |
Method | import |
Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but allows importing in-memory bytes data. |
Method | import |
Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but only supports importing from a tar file on disk. |
Method | import |
Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but only supports importing from another image, like the ``FROM`` Dockerfile parameter. |
Method | import |
Undocumented |
Method | import |
Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but only supports importing from a URL. |
Method | inspect |
Get image digest and platform information by contacting the registry. |
Method | inspect |
Get detailed information about an image. Similar to the ``docker inspect`` command, but only for images. |
Method | load |
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 |
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 |
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 |
Connect a container to a network. |
Method | create |
Create a network. Similar to the ``docker network create``. |
Method | disconnect |
Disconnect a container from a network. |
Method | inspect |
Get detailed information about a network. |
Method | networks |
List networks. Similar to the ``docker network ls`` command. |
Method | prune |
Delete unused networks |
Method | remove |
Remove a network. Similar to the ``docker network rm`` command. |
Inherited from PluginApiMixin
(via BuildApiMixin
, ConfigApiMixin
, ContainerApiMixin
, DaemonApiMixin
, ExecApiMixin
, ImageApiMixin
, NetworkApiMixin
):
Method | configure |
Configure a plugin. |
Method | create |
Create a new plugin. |
Method | disable |
Disable an installed plugin. |
Method | enable |
Enable an installed plugin. |
Method | inspect |
Retrieve plugin metadata. |
Method | plugin |
Retrieve list of privileges to be granted to a plugin. |
Method | plugins |
Retrieve a list of installed plugins. |
Method | pull |
Pull and install a plugin. After the plugin is installed, it can be enabled using :py:meth:`~enable_plugin`. |
Method | push |
Push a plugin to the registry. |
Method | remove |
Remove an installed plugin. |
Method | upgrade |
Upgrade an installed plugin. |
Inherited from SecretApiMixin
(via BuildApiMixin
, ConfigApiMixin
, ContainerApiMixin
, DaemonApiMixin
, ExecApiMixin
, ImageApiMixin
, NetworkApiMixin
, PluginApiMixin
):
Method | create |
Create a secret |
Method | inspect |
Retrieve secret metadata |
Method | remove |
Remove a secret |
Method | secrets |
List secrets |
Inherited from ServiceApiMixin
(via BuildApiMixin
, ConfigApiMixin
, ContainerApiMixin
, DaemonApiMixin
, ExecApiMixin
, ImageApiMixin
, NetworkApiMixin
, PluginApiMixin
, SecretApiMixin
):
Method | create |
Create a service. |
Method | inspect |
Return information about a service. |
Method | inspect |
Retrieve information about a task. |
Method | remove |
Stop and remove a service. |
Method | service |
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 |
Update a service. |
Inherited from SwarmApiMixin
(via BuildApiMixin
, ConfigApiMixin
, ContainerApiMixin
, DaemonApiMixin
, ExecApiMixin
, ImageApiMixin
, NetworkApiMixin
, PluginApiMixin
, SecretApiMixin
, ServiceApiMixin
):
Method | create |
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 |
Get the unlock key for this Swarm manager. |
Method | init |
Initialize a new Swarm using the current connected engine as the first node. |
Method | inspect |
Retrieve low-level information about a swarm node |
Method | inspect |
Retrieve low-level information about the current swarm. |
Method | join |
Make this Engine join a swarm that has already been created. |
Method | leave |
Leave a swarm. |
Method | nodes |
List swarm nodes. |
Method | remove |
Remove a node from the swarm. |
Method | unlock |
Unlock a locked swarm. |
Method | update |
Update the node's configuration |
Method | update |
Update the Swarm's configuration |
Inherited from VolumeApiMixin
(via BuildApiMixin
, ConfigApiMixin
, ContainerApiMixin
, DaemonApiMixin
, ExecApiMixin
, ImageApiMixin
, NetworkApiMixin
, PluginApiMixin
, SecretApiMixin
, ServiceApiMixin
, SwarmApiMixin
):
Method | create |
Create and register a named volume |
Method | inspect |
Retrieve volume info by name. |
Method | prune |
Delete unused volumes |
Method | remove |
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. |
Undocumented
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
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.