Networks on the Docker server.
| 92 | |
| 93 | |
| 94 | class NetworkCollection(Collection): |
| 95 | """ |
| 96 | Networks on the Docker server. |
| 97 | """ |
| 98 | model = Network |
| 99 | |
| 100 | def create(self, name, *args, **kwargs): |
| 101 | """ |
| 102 | Create a network. Similar to the ``docker network create``. |
| 103 | |
| 104 | Args: |
| 105 | name (str): Name of the network |
| 106 | driver (str): Name of the driver used to create the network |
| 107 | options (dict): Driver options as a key-value dictionary |
| 108 | ipam (IPAMConfig): Optional custom IP scheme for the network. |
| 109 | check_duplicate (bool): Request daemon to check for networks with |
| 110 | same name. Default: ``None``. |
| 111 | internal (bool): Restrict external access to the network. Default |
| 112 | ``False``. |
| 113 | labels (dict): Map of labels to set on the network. Default |
| 114 | ``None``. |
| 115 | enable_ipv6 (bool): Enable IPv6 on the network. Default ``False``. |
| 116 | attachable (bool): If enabled, and the network is in the global |
| 117 | scope, non-service containers on worker nodes will be able to |
| 118 | connect to the network. |
| 119 | scope (str): Specify the network's scope (``local``, ``global`` or |
| 120 | ``swarm``) |
| 121 | ingress (bool): If set, create an ingress network which provides |
| 122 | the routing-mesh in swarm mode. |
| 123 | |
| 124 | Returns: |
| 125 | (:py:class:`Network`): The network that was created. |
| 126 | |
| 127 | Raises: |
| 128 | :py:class:`docker.errors.APIError` |
| 129 | If the server returns an error. |
| 130 | |
| 131 | Example: |
| 132 | A network using the bridge driver: |
| 133 | |
| 134 | >>> client.networks.create("network1", driver="bridge") |
| 135 | |
| 136 | You can also create more advanced networks with custom IPAM |
| 137 | configurations. For example, setting the subnet to |
| 138 | ``192.168.52.0/24`` and gateway address to ``192.168.52.254``. |
| 139 | |
| 140 | .. code-block:: python |
| 141 | |
| 142 | >>> ipam_pool = docker.types.IPAMPool( |
| 143 | subnet='192.168.52.0/24', |
| 144 | gateway='192.168.52.254' |
| 145 | ) |
| 146 | >>> ipam_config = docker.types.IPAMConfig( |
| 147 | pool_configs=[ipam_pool] |
| 148 | ) |
| 149 | >>> client.networks.create( |
| 150 | "network1", |
| 151 | driver="bridge", |