github.com/sld880311/docker@v0.0.0-20200524143708-d5593973a475/docs/reference/commandline/network_create.md (about) 1 --- 2 title: "network create" 3 description: "The network create command description and usage" 4 keywords: "network, create" 5 --- 6 7 <!-- This file is maintained within the docker/docker Github 8 repository at https://github.com/docker/docker/. Make all 9 pull requests against that repo. If you see this file in 10 another repository, consider it read-only there, as it will 11 periodically be overwritten by the definitive file. Pull 12 requests which include edits to this file in other repositories 13 will be rejected. 14 --> 15 16 # network create 17 18 ```markdown 19 Usage: docker network create [OPTIONS] NETWORK 20 21 Create a network 22 23 Options: 24 --attachable Enable manual container attachment 25 --aux-address value Auxiliary IPv4 or IPv6 addresses used by Network 26 driver (default map[]) 27 -d, --driver string Driver to manage the Network (default "bridge") 28 --gateway value IPv4 or IPv6 Gateway for the master subnet (default []) 29 --help Print usage 30 --internal Restrict external access to the network 31 --ip-range value Allocate container ip from a sub-range (default []) 32 --ipam-driver string IP Address Management Driver (default "default") 33 --ipam-opt value Set IPAM driver specific options (default map[]) 34 --ipv6 Enable IPv6 networking 35 --label value Set metadata on a network (default []) 36 -o, --opt value Set driver specific options (default map[]) 37 --subnet value Subnet in CIDR format that represents a 38 network segment (default []) 39 ``` 40 41 ## Description 42 43 Creates a new network. The `DRIVER` accepts `bridge` or `overlay` which are the 44 built-in network drivers. If you have installed a third party or your own custom 45 network driver you can specify that `DRIVER` here also. If you don't specify the 46 `--driver` option, the command automatically creates a `bridge` network for you. 47 When you install Docker Engine it creates a `bridge` network automatically. This 48 network corresponds to the `docker0` bridge that Engine has traditionally relied 49 on. When you launch a new container with `docker run` it automatically connects to 50 this bridge network. You cannot remove this default bridge network, but you can 51 create new ones using the `network create` command. 52 53 ```bash 54 $ docker network create -d bridge my-bridge-network 55 ``` 56 57 Bridge networks are isolated networks on a single Engine installation. If you 58 want to create a network that spans multiple Docker hosts each running an 59 Engine, you must create an `overlay` network. Unlike `bridge` networks, overlay 60 networks require some pre-existing conditions before you can create one. These 61 conditions are: 62 63 * Access to a key-value store. Engine supports Consul, Etcd, and ZooKeeper (Distributed store) key-value stores. 64 * A cluster of hosts with connectivity to the key-value store. 65 * A properly configured Engine `daemon` on each host in the cluster. 66 67 The `dockerd` options that support the `overlay` network are: 68 69 * `--cluster-store` 70 * `--cluster-store-opt` 71 * `--cluster-advertise` 72 73 To read more about these options and how to configure them, see ["*Get started 74 with multi-host network*"](https://docs.docker.com/engine/userguide/networking/get-started-overlay). 75 76 While not required, it is a good idea to install Docker Swarm to 77 manage the cluster that makes up your network. Swarm provides sophisticated 78 discovery and server management tools that can assist your implementation. 79 80 Once you have prepared the `overlay` network prerequisites you simply choose a 81 Docker host in the cluster and issue the following to create the network: 82 83 ```bash 84 $ docker network create -d overlay my-multihost-network 85 ``` 86 87 Network names must be unique. The Docker daemon attempts to identify naming 88 conflicts but this is not guaranteed. It is the user's responsibility to avoid 89 name conflicts. 90 91 ## Examples 92 93 ### Connect containers 94 95 When you start a container, use the `--network` flag to connect it to a network. 96 This example adds the `busybox` container to the `mynet` network: 97 98 ```bash 99 $ docker run -itd --network=mynet busybox 100 ``` 101 102 If you want to add a container to a network after the container is already 103 running, use the `docker network connect` subcommand. 104 105 You can connect multiple containers to the same network. Once connected, the 106 containers can communicate using only another container's IP address or name. 107 For `overlay` networks or custom plugins that support multi-host connectivity, 108 containers connected to the same multi-host network but launched from different 109 Engines can also communicate in this way. 110 111 You can disconnect a container from a network using the `docker network 112 disconnect` command. 113 114 ### Specify advanced options 115 116 When you create a network, Engine creates a non-overlapping subnetwork for the 117 network by default. This subnetwork is not a subdivision of an existing 118 network. It is purely for ip-addressing purposes. You can override this default 119 and specify subnetwork values directly using the `--subnet` option. On a 120 `bridge` network you can only create a single subnet: 121 122 ```bash 123 $ docker network create --driver=bridge --subnet=192.168.0.0/16 br0 124 ``` 125 126 Additionally, you also specify the `--gateway` `--ip-range` and `--aux-address` 127 options. 128 129 ```bash 130 $ docker network create \ 131 --driver=bridge \ 132 --subnet=172.28.0.0/16 \ 133 --ip-range=172.28.5.0/24 \ 134 --gateway=172.28.5.254 \ 135 br0 136 ``` 137 138 If you omit the `--gateway` flag the Engine selects one for you from inside a 139 preferred pool. For `overlay` networks and for network driver plugins that 140 support it you can create multiple subnetworks. 141 142 ```bash 143 $ docker network create -d overlay \ 144 --subnet=192.168.0.0/16 \ 145 --subnet=192.170.0.0/16 \ 146 --gateway=192.168.0.100 \ 147 --gateway=192.170.0.100 \ 148 --ip-range=192.168.1.0/24 \ 149 --aux-address="my-router=192.168.1.5" --aux-address="my-switch=192.168.1.6" \ 150 --aux-address="my-printer=192.170.1.5" --aux-address="my-nas=192.170.1.6" \ 151 my-multihost-network 152 ``` 153 154 Be sure that your subnetworks do not overlap. If they do, the network create 155 fails and Engine returns an error. 156 157 ### Bridge driver options 158 159 When creating a custom network, the default network driver (i.e. `bridge`) has 160 additional options that can be passed. The following are those options and the 161 equivalent docker daemon flags used for docker0 bridge: 162 163 | Option | Equivalent | Description | 164 |--------------------------------------------------|-------------|-------------------------------------------------------| 165 | `com.docker.network.bridge.name` | - | bridge name to be used when creating the Linux bridge | 166 | `com.docker.network.bridge.enable_ip_masquerade` | `--ip-masq` | Enable IP masquerading | 167 | `com.docker.network.bridge.enable_icc` | `--icc` | Enable or Disable Inter Container Connectivity | 168 | `com.docker.network.bridge.host_binding_ipv4` | `--ip` | Default IP when binding container ports | 169 | `com.docker.network.driver.mtu` | `--mtu` | Set the containers network MTU | 170 171 The following arguments can be passed to `docker network create` for any 172 network driver, again with their approximate equivalents to `docker daemon`. 173 174 | Argument | Equivalent | Description | 175 |--------------|----------------|--------------------------------------------| 176 | `--gateway` | - | IPv4 or IPv6 Gateway for the master subnet | 177 | `--ip-range` | `--fixed-cidr` | Allocate IPs from a range | 178 | `--internal` | - | Restrict external access to the network | 179 | `--ipv6` | `--ipv6` | Enable IPv6 networking | 180 | `--subnet` | `--bip` | Subnet for network | 181 182 For example, let's use `-o` or `--opt` options to specify an IP address binding 183 when publishing ports: 184 185 ```bash 186 $ docker network create \ 187 -o "com.docker.network.bridge.host_binding_ipv4"="172.19.0.1" \ 188 simple-network 189 ``` 190 191 ### Network internal mode 192 193 By default, when you connect a container to an `overlay` network, Docker also 194 connects a bridge network to it to provide external connectivity. If you want 195 to create an externally isolated `overlay` network, you can specify the 196 `--internal` option. 197 198 ## Related commands 199 200 * [network inspect](network_inspect.md) 201 * [network connect](network_connect.md) 202 * [network disconnect](network_disconnect.md) 203 * [network ls](network_ls.md) 204 * [network rm](network_rm.md) 205 * [network prune](network_prune.md) 206 * [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/)