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