github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/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  [**--aux-address**=*map[]*]
    10  [**-d**|**--driver**=*DRIVER*]
    11  [**--gateway**=*[]*]
    12  [**--help**]
    13  [**--internal**]
    14  [**--ip-range**=*[]*]
    15  [**--ipam-driver**=*default*]
    16  [**--ipam-opt**=*map[]*]
    17  [**--ipv6**]
    18  [**--label**[=*[]*]]
    19  [**-o**|**--opt**=*map[]*]
    20  [**--subnet**=*[]*]
    21  NETWORK-NAME
    22  
    23  # DESCRIPTION
    24  
    25  Creates a new network. The `DRIVER` accepts `bridge` or `overlay` which are the
    26  built-in network drivers. If you have installed a third party or your own custom
    27  network driver you can specify that `DRIVER` here also. If you don't specify the
    28  `--driver` option, the command automatically creates a `bridge` network for you.
    29  When you install Docker Engine it creates a `bridge` network automatically. This
    30  network corresponds to the `docker0` bridge that Engine has traditionally relied
    31  on. When launch a new container with  `docker run` it automatically connects to
    32  this bridge network. You cannot remove this default bridge network but you can
    33  create new ones using the `network create` command.
    34  
    35  ```bash
    36  $ docker network create -d bridge my-bridge-network
    37  ```
    38  
    39  Bridge networks are isolated networks on a single Engine installation. If you
    40  want to create a network that spans multiple Docker hosts each running an
    41  Engine, you must create an `overlay` network. Unlike `bridge` networks overlay
    42  networks require some pre-existing conditions before you can create one. These
    43  conditions are:
    44  
    45  * Access to a key-value store. Engine supports Consul, Etcd, and Zookeeper (Distributed store) key-value stores.
    46  * A cluster of hosts with connectivity to the key-value store.
    47  * A properly configured Engine `daemon` on each host in the cluster.
    48  
    49  The `docker daemon` options that support the `overlay` network are:
    50  
    51  * `--cluster-store`
    52  * `--cluster-store-opt`
    53  * `--cluster-advertise`
    54  
    55  To read more about these options and how to configure them, see ["*Get started
    56  with multi-host
    57  network*"](https://docs.docker.com/engine/userguide/networking/get-started-overlay/).
    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
    98  network by default. This subnetwork is not a subdivision of an existing network.
    99  It is purely for ip-addressing purposes. You can override this default and
   100  specify subnetwork values directly using the `--subnet` option. On a
   101  `bridge` network you can only create a single subnet:
   102  
   103  ```bash
   104  docker network create -d bridge --subnet=192.168.0.0/16 br0
   105  ```
   106  Additionally, you also specify the `--gateway` `--ip-range` and `--aux-address` options.
   107  
   108  ```bash
   109  network create --driver=bridge --subnet=172.28.0.0/16 --ip-range=172.28.5.0/24 --gateway=172.28.5.254 br0
   110  ```
   111  
   112  If you omit the `--gateway` flag the Engine selects one for you from inside a
   113  preferred pool. For `overlay` networks and for network driver plugins that
   114  support it you can create multiple subnetworks.
   115  
   116  ```bash
   117  docker network create -d overlay
   118    --subnet=192.168.0.0/16 --subnet=192.170.0.0/16
   119    --gateway=192.168.0.100 --gateway=192.170.0.100
   120    --ip-range=192.168.1.0/24
   121    --aux-address a=192.168.1.5 --aux-address b=192.168.1.6
   122    --aux-address a=192.170.1.5 --aux-address b=192.170.1.6
   123    my-multihost-network
   124  ```
   125  Be sure that your subnetworks do not overlap. If they do, the network create fails and Engine returns an error.
   126  
   127  ### Network internal mode
   128  
   129  By default, when you connect a container to an `overlay` network, Docker also connects a bridge network to it to provide external connectivity.
   130  If you want to create an externally isolated `overlay` network, you can specify the `--internal` option.
   131  
   132  # OPTIONS
   133  **--aux-address**=map[]
   134    Auxiliary ipv4 or ipv6 addresses used by network driver
   135  
   136  **-d**, **--driver**=*DRIVER*
   137    Driver to manage the Network bridge or overlay. The default is bridge.
   138  
   139  **--gateway**=[]
   140    ipv4 or ipv6 Gateway for the master subnet
   141  
   142  **--help**
   143    Print usage
   144  
   145  **--internal**
   146    Restricts external access to the network
   147  
   148  **--ip-range**=[]
   149    Allocate container ip from a sub-range
   150  
   151  **--ipam-driver**=*default*
   152    IP Address Management Driver
   153  
   154  **--ipam-opt**=map[]
   155    Set custom IPAM driver options
   156  
   157  **--ipv6**
   158    Enable IPv6 networking
   159  
   160  **--label**=*label*
   161     Set metadata for a network
   162  
   163  **-o**, **--opt**=map[]
   164    Set custom driver options
   165  
   166  **--subnet**=[]
   167    Subnet in CIDR format that represents a network segment
   168  
   169  # HISTORY
   170  OCT 2015, created by Mary Anthony <mary@docker.com>