github.com/tompao/docker@v1.9.1/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 Usage: docker network create [OPTIONS] NETWORK-NAME 14 15 Creates a new network with a name specified by the user 16 17 --aux-address=map[] Auxiliary ipv4 or ipv6 addresses used by network driver 18 -d --driver=DRIVER Driver to manage the Network bridge or overlay. The default is bridge. 19 --gateway=[] ipv4 or ipv6 Gateway for the master subnet 20 --help=false Print usage 21 --ip-range=[] Allocate container ip from a sub-range 22 --ipam-driver=default IP Address Management Driver 23 -o --opt=map[] Set custom network plugin options 24 --subnet=[] Subnet in CIDR format that represents a network segment 25 26 Creates a new network. The `DRIVER` accepts `bridge` or `overlay` which are the 27 built-in network drivers. If you have installed a third party or your own custom 28 network driver you can specify that `DRIVER` here also. If you don't specify the 29 `--driver` option, the command automatically creates a `bridge` network for you. 30 When you install Docker Engine it creates a `bridge` network automatically. This 31 network corresponds to the `docker0` bridge that Engine has traditionally relied 32 on. When launch a new container with `docker run` it automatically connects to 33 this bridge network. You cannot remove this default bridge network but you can 34 create new ones using the `network create` command. 35 36 ```bash 37 $ docker network create -d bridge my-bridge-network 38 ``` 39 40 Bridge networks are isolated networks on a single Engine installation. If you 41 want to create a network that spans multiple Docker hosts each running an 42 Engine, you must create an `overlay` network. Unlike `bridge` networks overlay 43 networks require some pre-existing conditions before you can create one. These 44 conditions are: 45 46 * Access to a key-value store. Engine supports Consul, Etcd, and ZooKeeper (Distributed store) key-value stores. 47 * A cluster of hosts with connectivity to the key-value store. 48 * A properly configured Engine `daemon` on each host in the cluster. 49 50 The `docker daemon` options that support the `overlay` network are: 51 52 * `--cluster-store` 53 * `--cluster-store-opt` 54 * `--cluster-advertise` 55 56 To read more about these options and how to configure them, see ["*Get started 57 with multi-host network*"](../../userguide/networking/get-started-overlay.md). 58 59 It is also a good idea, though not required, that you install Docker Swarm on to 60 manage the cluster that makes up your network. Swarm provides sophisticated 61 discovery and server management that can assist your implementation. 62 63 Once you have prepared the `overlay` network prerequisites you simply choose a 64 Docker host in the cluster and issue the following to create the network: 65 66 ```bash 67 $ docker network create -d overlay my-multihost-network 68 ``` 69 70 Network names must be unique. The Docker daemon attempts to identify naming 71 conflicts but this is not guaranteed. It is the user's responsibility to avoid 72 name conflicts. 73 74 ## Connect containers 75 76 When you start a container use the `--net` flag to connect it to a network. 77 This adds the `busybox` container to the `mynet` network. 78 79 ```bash 80 $ docker run -itd --net=mynet busybox 81 ``` 82 83 If you want to add a container to a network after the container is already 84 running use the `docker network connect` subcommand. 85 86 You can connect multiple containers to the same network. Once connected, the 87 containers can communicate using only another container's IP address or name. 88 For `overlay` networks or custom plugins that support multi-host connectivity, 89 containers connected to the same multi-host network but launched from different 90 Engines can also communicate in this way. 91 92 You can disconnect a container from a network using the `docker network 93 disconnect` command. 94 95 ## Specifying advanced options 96 97 When you create a network, Engine creates a non-overlapping subnetwork for the network by default. This subnetwork is not a subdivision of an existing network. It is purely for ip-addressing purposes. You can override this default and specify subnetwork values directly using the the `--subnet` option. On a `bridge` network you can only create a single subnet: 98 99 ```bash 100 docker network create -d --subnet=192.168.0.0/16 101 ``` 102 Additionally, you also specify the `--gateway` `--ip-range` and `--aux-address` options. 103 104 ```bash 105 network create --driver=bridge --subnet=172.28.0.0/16 --ip-range=172.28.5.0/24 --gateway=172.28.5.254 br0 106 ``` 107 108 If you omit the `--gateway` flag the Engine selects one for you from inside a 109 preferred pool. For `overlay` networks and for network driver plugins that 110 support it you can create multiple subnetworks. 111 112 ```bash 113 docker network create -d overlay 114 --subnet=192.168.0.0/16 --subnet=192.170.0.0/16 115 --gateway=192.168.0.100 --gateway=192.170.0.100 116 --ip-range=192.168.1.0/24 117 --aux-address a=192.168.1.5 --aux-address b=192.168.1.6 118 --aux-address a=192.170.1.5 --aux-address b=192.170.1.6 119 my-multihost-newtork 120 ``` 121 Be sure that your subnetworks do not overlap. If they do, the network create fails and Engine returns an error. 122 123 ## Related information 124 125 * [network inspect](network_inspect.md) 126 * [network connect](network_connect.md) 127 * [network disconnect](network_disconnect.md) 128 * [network ls](network_ls.md) 129 * [network rm](network_rm.md) 130 * [Understand Docker container networks](../../userguide/networking/dockernetworks.md)