github.com/jen20/docker@v1.13.1/man/docker-network-create.1.md (about)

     1  % DOCKER(1) Docker User Manuals
     2  % Docker Community
     3  % OCT 2015
     4  # NAME
     5  docker-network-create - create a new network
     6  
     7  # SYNOPSIS
     8  **docker network create**
     9  [**--attachable**]
    10  [**--aux-address**=*map[]*]
    11  [**-d**|**--driver**=*DRIVER*]
    12  [**--gateway**=*[]*]
    13  [**--help**]
    14  [**--internal**]
    15  [**--ip-range**=*[]*]
    16  [**--ipam-driver**=*default*]
    17  [**--ipam-opt**=*map[]*]
    18  [**--ipv6**]
    19  [**--label**[=*[]*]]
    20  [**-o**|**--opt**=*map[]*]
    21  [**--subnet**=*[]*]
    22  NETWORK-NAME
    23  
    24  # DESCRIPTION
    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 `dockerd` 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
    58  network*"](https://docs.docker.com/engine/userguide/networking/get-started-overlay/).
    59  
    60  It is also a good idea, though not required, that you install Docker Swarm on to
    61  manage the cluster that makes up your network. Swarm provides sophisticated
    62  discovery and server management that can assist your implementation.
    63  
    64  Once you have prepared the `overlay` network prerequisites you simply choose a
    65  Docker host in the cluster and issue the following to create the network:
    66  
    67  ```bash
    68  $ docker network create -d overlay my-multihost-network
    69  ```
    70  
    71  Network names must be unique. The Docker daemon attempts to identify naming
    72  conflicts but this is not guaranteed. It is the user's responsibility to avoid
    73  name conflicts.
    74  
    75  ## Connect containers
    76  
    77  When you start a container use the `--network` flag to connect it to a network.
    78  This adds the `busybox` container to the `mynet` network.
    79  
    80  ```bash
    81  $ docker run -itd --network=mynet busybox
    82  ```
    83  
    84  If you want to add a container to a network after the container is already
    85  running use the `docker network connect` subcommand.
    86  
    87  You can connect multiple containers to the same network. Once connected, the
    88  containers can communicate using only another container's IP address or name.
    89  For `overlay` networks or custom plugins that support multi-host connectivity,
    90  containers connected to the same multi-host network but launched from different
    91  Engines can also communicate in this way.
    92  
    93  You can disconnect a container from a network using the `docker network
    94  disconnect` command.
    95  
    96  ## Specifying advanced options
    97  
    98  When you create a network, Engine creates a non-overlapping subnetwork for the
    99  network by default. This subnetwork is not a subdivision of an existing network.
   100  It is purely for ip-addressing purposes. You can override this default and
   101  specify subnetwork values directly using the `--subnet` option. On a
   102  `bridge` network you can only create a single subnet:
   103  
   104  ```bash
   105  $ docker network create -d bridge --subnet=192.168.0.0/16 br0
   106  ```
   107  
   108  Additionally, you also specify the `--gateway` `--ip-range` and `--aux-address`
   109  options.
   110  
   111  ```bash
   112  $ docker network create \
   113    --driver=bridge \
   114    --subnet=172.28.0.0/16 \
   115    --ip-range=172.28.5.0/24 \
   116    --gateway=172.28.5.254 \
   117    br0
   118  ```
   119  
   120  If you omit the `--gateway` flag the Engine selects one for you from inside a
   121  preferred pool. For `overlay` networks and for network driver plugins that
   122  support it you can create multiple subnetworks.
   123  
   124  ```bash
   125  $ docker network create -d overlay \
   126    --subnet=192.168.0.0/16 \
   127    --subnet=192.170.0.0/16 \
   128    --gateway=192.168.0.100 \ 
   129    --gateway=192.170.0.100 \
   130    --ip-range=192.168.1.0/24 \
   131    --aux-address="my-router=192.168.1.5" --aux-address="my-switch=192.168.1.6" \
   132    --aux-address="my-printer=192.170.1.5" --aux-address="my-nas=192.170.1.6" \
   133    my-multihost-network
   134  ```
   135  
   136  Be sure that your subnetworks do not overlap. If they do, the network create
   137  fails and Engine returns an error.
   138  
   139  ### Network internal mode
   140  
   141  By default, when you connect a container to an `overlay` network, Docker also
   142  connects a bridge network to it to provide external connectivity. If you want
   143  to create an externally isolated `overlay` network, you can specify the
   144  `--internal` option.
   145  
   146  # OPTIONS
   147  **--attachable**
   148    Enable manual container attachment
   149  
   150  **--aux-address**=map[]
   151    Auxiliary IPv4 or IPv6 addresses used by network driver
   152  
   153  **-d**, **--driver**=*DRIVER*
   154    Driver to manage the Network bridge or overlay. The default is bridge.
   155  
   156  **--gateway**=[]
   157    IPv4 or IPv6 Gateway for the master subnet
   158  
   159  **--help**
   160    Print usage
   161  
   162  **--internal**
   163    Restrict external access to the network
   164  
   165  **--ip-range**=[]
   166    Allocate container ip from a sub-range
   167  
   168  **--ipam-driver**=*default*
   169    IP Address Management Driver
   170  
   171  **--ipam-opt**=map[]
   172    Set custom IPAM driver options
   173  
   174  **--ipv6**
   175    Enable IPv6 networking
   176  
   177  **--label**=*label*
   178     Set metadata for a network
   179  
   180  **-o**, **--opt**=map[]
   181    Set custom driver options
   182  
   183  **--subnet**=[]
   184    Subnet in CIDR format that represents a network segment
   185  
   186  # HISTORY
   187  OCT 2015, created by Mary Anthony <mary@docker.com>