1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
<h1>docker network create</h1> <p><br></p> <p>Create a network</p> <h2 id="usage">Usage</h2> <div class="highlight"><pre class="highlight" data-language="">$ docker network create [OPTIONS] NETWORK
</pre></div> <p>Refer to the <a href="#options">options section</a> for an overview of available <a href="#options"><code class="language-plaintext highlighter-rouge">OPTIONS</code></a> for this command.</p> <h2 id="description">Description</h2> <p name="extended-description">Creates a new network. The <code class="language-plaintext highlighter-rouge">DRIVER</code> accepts <code class="language-plaintext highlighter-rouge">bridge</code> or <code class="language-plaintext highlighter-rouge">overlay</code> which are the built-in network drivers. If you have installed a third party or your own custom network driver you can specify that <code class="language-plaintext highlighter-rouge">DRIVER</code> here also. If you don’t specify the <code class="language-plaintext highlighter-rouge">--driver</code> option, the command automatically creates a <code class="language-plaintext highlighter-rouge">bridge</code> network for you. When you install Docker Engine it creates a <code class="language-plaintext highlighter-rouge">bridge</code> network automatically. This network corresponds to the <code class="language-plaintext highlighter-rouge">docker0</code> bridge that Engine has traditionally relied on. When you launch a new container with <code class="language-plaintext highlighter-rouge">docker run</code> it automatically connects to this bridge network. You cannot remove this default bridge network, but you can create new ones using the <code class="language-plaintext highlighter-rouge">network create</code> command.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker network create -d bridge my-bridge-network
</pre></div> <p>Bridge networks are isolated networks on a single Engine installation. If you want to create a network that spans multiple Docker hosts each running an Engine, you must create an <code class="language-plaintext highlighter-rouge">overlay</code> network. Unlike <code class="language-plaintext highlighter-rouge">bridge</code> networks, overlay networks require some pre-existing conditions before you can create one. These conditions are:</p> <ul> <li>Access to a key-value store. Engine supports Consul, Etcd, and ZooKeeper (Distributed store) key-value stores.</li> <li>A cluster of hosts with connectivity to the key-value store.</li> <li>A properly configured Engine <code class="language-plaintext highlighter-rouge">daemon</code> on each host in the cluster.</li> </ul> <p>The <code class="language-plaintext highlighter-rouge">dockerd</code> options that support the <code class="language-plaintext highlighter-rouge">overlay</code> network are:</p> <ul> <li><code class="language-plaintext highlighter-rouge">--cluster-store</code></li> <li><code class="language-plaintext highlighter-rouge">--cluster-store-opt</code></li> <li><code class="language-plaintext highlighter-rouge">--cluster-advertise</code></li> </ul> <p>To read more about these options and how to configure them, see <a href="https://docs.docker.com/engine/userguide/networking/get-started-overlay">“<em>Get started with multi-host network</em>”</a>.</p> <p>While not required, it is a good idea to install Docker Swarm to manage the cluster that makes up your network. Swarm provides sophisticated discovery and server management tools that can assist your implementation.</p> <p>Once you have prepared the <code class="language-plaintext highlighter-rouge">overlay</code> network prerequisites you simply choose a Docker host in the cluster and issue the following to create the network:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker network create -d overlay my-multihost-network
</pre></div> <p>Network names must be unique. The Docker daemon attempts to identify naming conflicts but this is not guaranteed. It is the user’s responsibility to avoid name conflicts.</p> <h3 id="overlay-network-limitations">Overlay network limitations</h3> <p>You should create overlay networks with <code class="language-plaintext highlighter-rouge">/24</code> blocks (the default), which limits you to 256 IP addresses, when you create networks using the default VIP-based endpoint-mode. This recommendation addresses <a href="https://github.com/moby/moby/issues/30820">limitations with swarm mode</a>. If you need more than 256 IP addresses, do not increase the IP block size. You can either use <code class="language-plaintext highlighter-rouge">dnsrr</code> endpoint mode with an external load balancer, or use multiple smaller overlay networks. See <a href="https://docs.docker.com/network/overlay#configure-service-discovery">Configure service discovery</a> for more information about different endpoint modes.</p> <p>For example uses of this command, refer to the <a href="#examples">examples section</a> below.</p> <h2 id="options">Options</h2> <table> <thead> <tr> <td>Name, shorthand</td> <td>Default</td> <td>Description</td> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">--attachable</code></td> <td></td> <td>Enable manual container attachment</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--aux-address</code></td> <td></td> <td>Auxiliary IPv4 or IPv6 addresses used by Network driver</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--config-from</code></td> <td></td> <td>The network from which to copy the configuration</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--config-only</code></td> <td></td> <td>Create a configuration only network</td> </tr> <tr> <td>
<code class="language-plaintext highlighter-rouge">--driver</code> , <code class="language-plaintext highlighter-rouge">-d</code>
</td> <td><code class="language-plaintext highlighter-rouge">bridge</code></td> <td>Driver to manage the Network</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--gateway</code></td> <td></td> <td>IPv4 or IPv6 Gateway for the master subnet</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--ingress</code></td> <td></td> <td>Create swarm routing-mesh network</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--internal</code></td> <td></td> <td>Restrict external access to the network</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--ip-range</code></td> <td></td> <td>Allocate container ip from a sub-range</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--ipam-driver</code></td> <td></td> <td>IP Address Management Driver</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--ipam-opt</code></td> <td></td> <td>Set IPAM driver specific options</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--ipv6</code></td> <td></td> <td>Enable IPv6 networking</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--label</code></td> <td></td> <td>Set metadata on a network</td> </tr> <tr> <td>
<code class="language-plaintext highlighter-rouge">--opt</code> , <code class="language-plaintext highlighter-rouge">-o</code>
</td> <td></td> <td>Set driver specific options</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--scope</code></td> <td></td> <td>Control the network's scope</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--subnet</code></td> <td></td> <td>Subnet in CIDR format that represents a network segment</td> </tr> </tbody> </table> <h2 id="examples">Examples</h2> <h3 id="connect-containers">Connect containers</h3> <p>When you start a container, use the <code class="language-plaintext highlighter-rouge">--network</code> flag to connect it to a network. This example adds the <code class="language-plaintext highlighter-rouge">busybox</code> container to the <code class="language-plaintext highlighter-rouge">mynet</code> network:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker run -itd --network=mynet busybox
</pre></div> <p>If you want to add a container to a network after the container is already running, use the <code class="language-plaintext highlighter-rouge">docker network connect</code> subcommand.</p> <p>You can connect multiple containers to the same network. Once connected, the containers can communicate using only another container’s IP address or name. For <code class="language-plaintext highlighter-rouge">overlay</code> networks or custom plugins that support multi-host connectivity, containers connected to the same multi-host network but launched from different Engines can also communicate in this way.</p> <p>You can disconnect a container from a network using the <code class="language-plaintext highlighter-rouge">docker network disconnect</code> command.</p> <h3 id="specify-advanced-options">Specify advanced options</h3> <p>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 <code class="language-plaintext highlighter-rouge">--subnet</code> option. On a <code class="language-plaintext highlighter-rouge">bridge</code> network you can only create a single subnet:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker network create --driver=bridge --subnet=192.168.0.0/16 br0
</pre></div> <p>Additionally, you also specify the <code class="language-plaintext highlighter-rouge">--gateway</code> <code class="language-plaintext highlighter-rouge">--ip-range</code> and <code class="language-plaintext highlighter-rouge">--aux-address</code> options.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker network create \
--driver=bridge \
--subnet=172.28.0.0/16 \
--ip-range=172.28.5.0/24 \
--gateway=172.28.5.254 \
br0
</pre></div> <p>If you omit the <code class="language-plaintext highlighter-rouge">--gateway</code> flag the Engine selects one for you from inside a preferred pool. For <code class="language-plaintext highlighter-rouge">overlay</code> networks and for network driver plugins that support it you can create multiple subnetworks. This example uses two <code class="language-plaintext highlighter-rouge">/25</code> subnet mask to adhere to the current guidance of not having more than 256 IPs in a single overlay network. Each of the subnetworks has 126 usable addresses.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker network create -d overlay \
--subnet=192.168.10.0/25 \
--subnet=192.168.20.0/25 \
--gateway=192.168.10.100 \
--gateway=192.168.20.100 \
--aux-address="my-router=192.168.10.5" --aux-address="my-switch=192.168.10.6" \
--aux-address="my-printer=192.168.20.5" --aux-address="my-nas=192.168.20.6" \
my-multihost-network
</pre></div> <p>Be sure that your subnetworks do not overlap. If they do, the network create fails and Engine returns an error.</p> <h3 id="bridge-driver-options">Bridge driver options</h3> <p>When creating a custom network, the default network driver (i.e. <code class="language-plaintext highlighter-rouge">bridge</code>) has additional options that can be passed. The following are those options and the equivalent docker daemon flags used for docker0 bridge:</p> <table> <thead> <tr> <th>Option</th> <th>Equivalent</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">com.docker.network.bridge.name</code></td> <td>-</td> <td>Bridge name to be used when creating the Linux bridge</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">com.docker.network.bridge.enable_ip_masquerade</code></td> <td><code class="language-plaintext highlighter-rouge">--ip-masq</code></td> <td>Enable IP masquerading</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">com.docker.network.bridge.enable_icc</code></td> <td><code class="language-plaintext highlighter-rouge">--icc</code></td> <td>Enable or Disable Inter Container Connectivity</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">com.docker.network.bridge.host_binding_ipv4</code></td> <td><code class="language-plaintext highlighter-rouge">--ip</code></td> <td>Default IP when binding container ports</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">com.docker.network.driver.mtu</code></td> <td><code class="language-plaintext highlighter-rouge">--mtu</code></td> <td>Set the containers network MTU</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">com.docker.network.container_iface_prefix</code></td> <td>-</td> <td>Set a custom prefix for container interfaces</td> </tr> </tbody> </table> <p>The following arguments can be passed to <code class="language-plaintext highlighter-rouge">docker network create</code> for any network driver, again with their approximate equivalents to <code class="language-plaintext highlighter-rouge">docker daemon</code>.</p> <table> <thead> <tr> <th>Argument</th> <th>Equivalent</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">--gateway</code></td> <td>-</td> <td>IPv4 or IPv6 Gateway for the master subnet</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--ip-range</code></td> <td><code class="language-plaintext highlighter-rouge">--fixed-cidr</code></td> <td>Allocate IPs from a range</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--internal</code></td> <td>-</td> <td>Restrict external access to the network</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--ipv6</code></td> <td><code class="language-plaintext highlighter-rouge">--ipv6</code></td> <td>Enable IPv6 networking</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--subnet</code></td> <td><code class="language-plaintext highlighter-rouge">--bip</code></td> <td>Subnet for network</td> </tr> </tbody> </table> <p>For example, let’s use <code class="language-plaintext highlighter-rouge">-o</code> or <code class="language-plaintext highlighter-rouge">--opt</code> options to specify an IP address binding when publishing ports:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker network create \
-o "com.docker.network.bridge.host_binding_ipv4"="172.19.0.1" \
simple-network
</pre></div> <h3 id="network-internal-mode">Network internal mode</h3> <p>By default, when you connect a container to an <code class="language-plaintext highlighter-rouge">overlay</code> network, Docker also connects a bridge network to it to provide external connectivity. If you want to create an externally isolated <code class="language-plaintext highlighter-rouge">overlay</code> network, you can specify the <code class="language-plaintext highlighter-rouge">--internal</code> option.</p> <h3 id="network-ingress-mode">Network ingress mode</h3> <p>You can create the network which will be used to provide the routing-mesh in the swarm cluster. You do so by specifying <code class="language-plaintext highlighter-rouge">--ingress</code> when creating the network. Only one ingress network can be created at the time. The network can be removed only if no services depend on it. Any option available when creating an overlay network is also available when creating the ingress network, besides the <code class="language-plaintext highlighter-rouge">--attachable</code> option.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker network create -d overlay \
--subnet=10.11.0.0/16 \
--ingress \
--opt com.docker.network.driver.mtu=9216 \
--opt encrypted=true \
my-ingress-network
</pre></div> <h2 id="parent-command">Parent command</h2> <table> <thead> <tr> <th style="text-align: left">Command</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><a href="../network/index">docker network</a></td> <td style="text-align: left">Manage networks</td> </tr> </tbody> </table> <h2 id="related-commands">Related commands</h2> <table> <thead> <tr> <td>Command</td> <td>Description</td> </tr> </thead> <tbody> <tr> <td><a href="../network_connect/index">docker network connect</a></td> <td>Connect a container to a network</td> </tr> <tr> <td><a href="index">docker network create</a></td> <td>Create a network</td> </tr> <tr> <td><a href="../network_disconnect/index">docker network disconnect</a></td> <td>Disconnect a container from a network</td> </tr> <tr> <td><a href="../network_inspect/index">docker network inspect</a></td> <td>Display detailed information on one or more networks</td> </tr> <tr> <td><a href="../network_ls/index">docker network ls</a></td> <td>List networks</td> </tr> <tr> <td><a href="../network_prune/index">docker network prune</a></td> <td>Remove all unused networks</td> </tr> <tr> <td><a href="../network_rm/index">docker network rm</a></td> <td>Remove one or more networks</td> </tr> </tbody> </table> <div class="_attribution">
<p class="_attribution-p">
© 2019 Docker, Inc.<br>Licensed under the Apache License, Version 2.0.<br>Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.<br>Docker, Inc. and other parties may also have trademark rights in other terms used herein.<br>
<a href="https://docs.docker.com/engine/reference/commandline/network_create/" class="_attribution-link">https://docs.docker.com/engine/reference/commandline/network_create/</a>
</p>
</div>
|