Create a network. Similar to the ``docker network create``. Args: name (str): Name of the network driver (str): Name of the driver used to create the network options (dict): Driver options as a key-value dictionary ipam (IPAMConfig):
(self, name, driver=None, options=None, ipam=None,
check_duplicate=None, internal=False, labels=None,
enable_ipv6=False, attachable=None, scope=None,
ingress=None)
| 38 | return self._result(res, json=True) |
| 39 | |
| 40 | def create_network(self, name, driver=None, options=None, ipam=None, |
| 41 | check_duplicate=None, internal=False, labels=None, |
| 42 | enable_ipv6=False, attachable=None, scope=None, |
| 43 | ingress=None): |
| 44 | """ |
| 45 | Create a network. Similar to the ``docker network create``. |
| 46 | |
| 47 | Args: |
| 48 | name (str): Name of the network |
| 49 | driver (str): Name of the driver used to create the network |
| 50 | options (dict): Driver options as a key-value dictionary |
| 51 | ipam (IPAMConfig): Optional custom IP scheme for the network. |
| 52 | check_duplicate (bool): Request daemon to check for networks with |
| 53 | same name. Default: ``None``. |
| 54 | internal (bool): Restrict external access to the network. Default |
| 55 | ``False``. |
| 56 | labels (dict): Map of labels to set on the network. Default |
| 57 | ``None``. |
| 58 | enable_ipv6 (bool): Enable IPv6 on the network. Default ``False``. |
| 59 | attachable (bool): If enabled, and the network is in the global |
| 60 | scope, non-service containers on worker nodes will be able to |
| 61 | connect to the network. |
| 62 | scope (str): Specify the network's scope (``local``, ``global`` or |
| 63 | ``swarm``) |
| 64 | ingress (bool): If set, create an ingress network which provides |
| 65 | the routing-mesh in swarm mode. |
| 66 | |
| 67 | Returns: |
| 68 | (dict): The created network reference object |
| 69 | |
| 70 | Raises: |
| 71 | :py:class:`docker.errors.APIError` |
| 72 | If the server returns an error. |
| 73 | |
| 74 | Example: |
| 75 | A network using the bridge driver: |
| 76 | |
| 77 | >>> client.api.create_network("network1", driver="bridge") |
| 78 | |
| 79 | You can also create more advanced networks with custom IPAM |
| 80 | configurations. For example, setting the subnet to |
| 81 | ``192.168.52.0/24`` and gateway address to ``192.168.52.254``. |
| 82 | |
| 83 | .. code-block:: python |
| 84 | |
| 85 | >>> ipam_pool = docker.types.IPAMPool( |
| 86 | subnet='192.168.52.0/24', |
| 87 | gateway='192.168.52.254' |
| 88 | ) |
| 89 | >>> ipam_config = docker.types.IPAMConfig( |
| 90 | pool_configs=[ipam_pool] |
| 91 | ) |
| 92 | >>> client.api.create_network("network1", driver="bridge", |
| 93 | ipam=ipam_config) |
| 94 | """ |
| 95 | if options is not None and not isinstance(options, dict): |
| 96 | raise TypeError('options must be a dictionary') |
| 97 |
no test coverage detected