github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/docs/reference/commandline/network_create.md (about)

     1  ---
     2  title: "network create"
     3  description: "The network create command description and usage"
     4  keywords: "network, create"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/cli GitHub
     8       repository at https://github.com/docker/cli/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # network create
    17  
    18  ```markdown
    19  Usage:	docker network create [OPTIONS] NETWORK
    20  
    21  Create a network
    22  
    23  Options:
    24        --attachable           Enable manual container attachment
    25        --ingress              Specify the network provides the routing-mesh
    26        --aux-address value    Auxiliary IPv4 or IPv6 addresses used by Network
    27                               driver (default map[])
    28    -d, --driver string        Driver to manage the Network (default "bridge")
    29        --gateway value        IPv4 or IPv6 Gateway for the master subnet (default [])
    30        --help                 Print usage
    31        --internal             Restrict external access to the network
    32        --ip-range value       Allocate container ip from a sub-range (default [])
    33        --ipam-driver string   IP Address Management Driver (default "default")
    34        --ipam-opt value       Set IPAM driver specific options (default map[])
    35        --ipv6                 Enable IPv6 networking
    36        --label value          Set metadata on a network (default [])
    37    -o, --opt value            Set driver specific options (default map[])
    38        --subnet value         Subnet in CIDR format that represents a
    39                               network segment (default [])
    40        --scope value          Promote a network to swarm scope (value = [ local | swarm ])
    41        --config-only          Creates a configuration only network
    42        --config-from          The name of the network from which copying the configuration
    43  ```
    44  
    45  ## Description
    46  
    47  Creates a new network. The `DRIVER` accepts `bridge` or `overlay` which are the
    48  built-in network drivers. If you have installed a third party or your own custom
    49  network driver you can specify that `DRIVER` here also. If you don't specify the
    50  `--driver` option, the command automatically creates a `bridge` network for you.
    51  When you install Docker Engine it creates a `bridge` network automatically. This
    52  network corresponds to the `docker0` bridge that Engine has traditionally relied
    53  on. When you launch a new container with  `docker run` it automatically connects to
    54  this bridge network. You cannot remove this default bridge network, but you can
    55  create new ones using the `network create` command.
    56  
    57  ```bash
    58  $ docker network create -d bridge my-bridge-network
    59  ```
    60  
    61  Bridge networks are isolated networks on a single Engine installation. If you
    62  want to create a network that spans multiple Docker hosts each running an
    63  Engine, you must create an `overlay` network. Unlike `bridge` networks, overlay
    64  networks require some pre-existing conditions before you can create one. These
    65  conditions are:
    66  
    67  * Access to a key-value store. Engine supports Consul, Etcd, and ZooKeeper (Distributed store) key-value stores.
    68  * A cluster of hosts with connectivity to the key-value store.
    69  * A properly configured Engine `daemon` on each host in the cluster.
    70  
    71  The `dockerd` options that support the `overlay` network are:
    72  
    73  * `--cluster-store`
    74  * `--cluster-store-opt`
    75  * `--cluster-advertise`
    76  
    77  To read more about these options and how to configure them, see ["*Get started
    78  with multi-host network*"](https://docs.docker.com/engine/userguide/networking/get-started-overlay).
    79  
    80  While not required, it is a good idea to install Docker Swarm to
    81  manage the cluster that makes up your network. Swarm provides sophisticated
    82  discovery and server management tools that can assist your implementation.
    83  
    84  Once you have prepared the `overlay` network prerequisites you simply choose a
    85  Docker host in the cluster and issue the following to create the network:
    86  
    87  ```bash
    88  $ docker network create -d overlay my-multihost-network
    89  ```
    90  
    91  Network names must be unique. The Docker daemon attempts to identify naming
    92  conflicts but this is not guaranteed. It is the user's responsibility to avoid
    93  name conflicts.
    94  
    95  ### Overlay network limitations
    96  
    97  You should create overlay networks with `/24` blocks (the default), which limits
    98  you to 256 IP addresses, when you create networks using the default VIP-based
    99  endpoint-mode. This recommendation addresses
   100  [limitations with swarm mode](https://github.com/moby/moby/issues/30820). If you
   101  need more than 256 IP addresses, do not increase the IP block size. You can
   102  either use `dnsrr` endpoint mode with an external load balancer, or use multiple
   103  smaller overlay networks. See
   104  [Configure service discovery](https://docs.docker.com/engine/swarm/networking/#configure-service-discovery)
   105  for more information about different endpoint modes.
   106  
   107  ## Examples
   108  
   109  ### Connect containers
   110  
   111  When you start a container, use the `--network` flag to connect it to a network.
   112  This example adds the `busybox` container to the `mynet` network:
   113  
   114  ```bash
   115  $ docker run -itd --network=mynet busybox
   116  ```
   117  
   118  If you want to add a container to a network after the container is already
   119  running, use the `docker network connect` subcommand.
   120  
   121  You can connect multiple containers to the same network. Once connected, the
   122  containers can communicate using only another container's IP address or name.
   123  For `overlay` networks or custom plugins that support multi-host connectivity,
   124  containers connected to the same multi-host network but launched from different
   125  Engines can also communicate in this way.
   126  
   127  You can disconnect a container from a network using the `docker network
   128  disconnect` command.
   129  
   130  ### Specify advanced options
   131  
   132  When you create a network, Engine creates a non-overlapping subnetwork for the
   133  network by default. This subnetwork is not a subdivision of an existing
   134  network. It is purely for ip-addressing purposes. You can override this default
   135  and specify subnetwork values directly using the `--subnet` option. On a
   136  `bridge` network you can only create a single subnet:
   137  
   138  ```bash
   139  $ docker network create --driver=bridge --subnet=192.168.0.0/16 br0
   140  ```
   141  
   142  Additionally, you also specify the `--gateway` `--ip-range` and `--aux-address`
   143  options.
   144  
   145  ```bash
   146  $ docker network create \
   147    --driver=bridge \
   148    --subnet=172.28.0.0/16 \
   149    --ip-range=172.28.5.0/24 \
   150    --gateway=172.28.5.254 \
   151    br0
   152  ```
   153  
   154  If you omit the `--gateway` flag the Engine selects one for you from inside a
   155  preferred pool. For `overlay` networks and for network driver plugins that
   156  support it you can create multiple subnetworks. This example uses two `/25`
   157  subnet mask to adhere to the current guidance of not having more than 256 IPs in
   158  a single overlay network. Each of the subnetworks has 126 usable addresses.
   159  
   160  ```bash
   161  $ docker network create -d overlay \
   162    --subnet=192.168.1.0/25 \
   163    --subnet=192.170.2.0/25 \
   164    --gateway=192.168.1.100 \
   165    --gateway=192.170.2.100 \
   166    --aux-address="my-router=192.168.1.5" --aux-address="my-switch=192.168.1.6" \
   167    --aux-address="my-printer=192.170.1.5" --aux-address="my-nas=192.170.1.6" \
   168    my-multihost-network
   169  ```
   170  
   171  Be sure that your subnetworks do not overlap. If they do, the network create
   172  fails and Engine returns an error.
   173  
   174  ### Bridge driver options
   175  
   176  When creating a custom network, the default network driver (i.e. `bridge`) has
   177  additional options that can be passed. The following are those options and the
   178  equivalent docker daemon flags used for docker0 bridge:
   179  
   180  | Option                                           | Equivalent  | Description                                           |
   181  |--------------------------------------------------|-------------|-------------------------------------------------------|
   182  | `com.docker.network.bridge.name`                 | -           | bridge name to be used when creating the Linux bridge |
   183  | `com.docker.network.bridge.enable_ip_masquerade` | `--ip-masq` | Enable IP masquerading                                |
   184  | `com.docker.network.bridge.enable_icc`           | `--icc`     | Enable or Disable Inter Container Connectivity        |
   185  | `com.docker.network.bridge.host_binding_ipv4`    | `--ip`      | Default IP when binding container ports               |
   186  | `com.docker.network.driver.mtu`                  | `--mtu`     | Set the containers network MTU                        |
   187  
   188  The following arguments can be passed to `docker network create` for any
   189  network driver, again with their approximate equivalents to `docker daemon`.
   190  
   191  | Argument     | Equivalent     | Description                                |
   192  |--------------|----------------|--------------------------------------------|
   193  | `--gateway`  | -              | IPv4 or IPv6 Gateway for the master subnet |
   194  | `--ip-range` | `--fixed-cidr` | Allocate IPs from a range                  |
   195  | `--internal` | -              | Restrict external access to the network   |
   196  | `--ipv6`     | `--ipv6`       | Enable IPv6 networking                     |
   197  | `--subnet`   | `--bip`        | Subnet for network                         |
   198  
   199  For example, let's use `-o` or `--opt` options to specify an IP address binding
   200  when publishing ports:
   201  
   202  ```bash
   203  $ docker network create \
   204      -o "com.docker.network.bridge.host_binding_ipv4"="172.19.0.1" \
   205      simple-network
   206  ```
   207  
   208  ### Network internal mode
   209  
   210  By default, when you connect a container to an `overlay` network, Docker also
   211  connects a bridge network to it to provide external connectivity. If you want
   212  to create an externally isolated `overlay` network, you can specify the
   213  `--internal` option.
   214  
   215  ### Network ingress mode
   216  
   217  You can create the network which will be used to provide the routing-mesh in the
   218  swarm cluster. You do so by specifying `--ingress` when creating the network. Only
   219  one ingress network can be created at the time. The network can be removed only
   220  if no services depend on it. Any option available when creating an overlay network
   221  is also available when creating the ingress network, besides the `--attachable` option.
   222  
   223  ```bash
   224  $ docker network create -d overlay \
   225    --subnet=10.11.0.0/16 \
   226    --ingress \
   227    --opt com.docker.network.driver.mtu=9216 \
   228    --opt encrypted=true \
   229    my-ingress-network
   230  ```
   231  
   232  ## Related commands
   233  
   234  * [network inspect](network_inspect.md)
   235  * [network connect](network_connect.md)
   236  * [network disconnect](network_disconnect.md)
   237  * [network ls](network_ls.md)
   238  * [network rm](network_rm.md)
   239  * [network prune](network_prune.md)
   240  * [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/)