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