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