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