Return a client configured from environment variables. The environment variables used are the same as those used by the Docker command-line client. They are: .. envvar:: DOCKER_HOST The URL to the Docker host. .. envvar:: DOCKER_TLS_VERIFY
(cls, **kwargs)
| 46 | |
| 47 | @classmethod |
| 48 | def from_env(cls, **kwargs): |
| 49 | """ |
| 50 | Return a client configured from environment variables. |
| 51 | |
| 52 | The environment variables used are the same as those used by the |
| 53 | Docker command-line client. They are: |
| 54 | |
| 55 | .. envvar:: DOCKER_HOST |
| 56 | |
| 57 | The URL to the Docker host. |
| 58 | |
| 59 | .. envvar:: DOCKER_TLS_VERIFY |
| 60 | |
| 61 | Verify the host against a CA certificate. |
| 62 | |
| 63 | .. envvar:: DOCKER_CERT_PATH |
| 64 | |
| 65 | A path to a directory containing TLS certificates to use when |
| 66 | connecting to the Docker host. |
| 67 | |
| 68 | Args: |
| 69 | version (str): The version of the API to use. Set to ``auto`` to |
| 70 | automatically detect the server's version. Default: ``auto`` |
| 71 | timeout (int): Default timeout for API calls, in seconds. |
| 72 | max_pool_size (int): The maximum number of connections |
| 73 | to save in the pool. |
| 74 | environment (dict): The environment to read environment variables |
| 75 | from. Default: the value of ``os.environ`` |
| 76 | credstore_env (dict): Override environment variables when calling |
| 77 | the credential store process. |
| 78 | use_ssh_client (bool): If set to `True`, an ssh connection is |
| 79 | made via shelling out to the ssh client. Ensure the ssh |
| 80 | client is installed and configured on the host. |
| 81 | |
| 82 | Example: |
| 83 | |
| 84 | >>> import docker |
| 85 | >>> client = docker.from_env() |
| 86 | |
| 87 | .. _`SSL version`: |
| 88 | https://docs.python.org/3.5/library/ssl.html#ssl.PROTOCOL_TLSv1 |
| 89 | """ |
| 90 | timeout = kwargs.pop('timeout', DEFAULT_TIMEOUT_SECONDS) |
| 91 | max_pool_size = kwargs.pop('max_pool_size', DEFAULT_MAX_POOL_SIZE) |
| 92 | version = kwargs.pop('version', None) |
| 93 | use_ssh_client = kwargs.pop('use_ssh_client', False) |
| 94 | return cls( |
| 95 | timeout=timeout, |
| 96 | max_pool_size=max_pool_size, |
| 97 | version=version, |
| 98 | use_ssh_client=use_ssh_client, |
| 99 | **kwargs_from_env(**kwargs) |
| 100 | ) |
| 101 | |
| 102 | # Resources |
| 103 | @property |