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