2016-10-14 18:30:36 -04:00
|
|
|
---
|
|
|
|
title: "network create"
|
|
|
|
description: "The network create command description and usage"
|
2016-11-03 18:48:30 -04:00
|
|
|
keywords: "network, create"
|
2016-10-14 18:30:36 -04:00
|
|
|
---
|
2015-09-28 21:57:03 -04:00
|
|
|
|
2016-10-19 13:25:45 -04:00
|
|
|
<!-- This file is maintained within the docker/docker Github
|
|
|
|
repository at https://github.com/docker/docker/. Make all
|
|
|
|
pull requests against that repo. If you see this file in
|
|
|
|
another repository, consider it read-only there, as it will
|
|
|
|
periodically be overwritten by the definitive file. Pull
|
|
|
|
requests which include edits to this file in other repositories
|
|
|
|
will be rejected.
|
|
|
|
-->
|
|
|
|
|
2015-09-28 21:57:03 -04:00
|
|
|
# network create
|
|
|
|
|
2016-06-06 08:20:41 -04:00
|
|
|
```markdown
|
2016-08-31 05:36:45 -04:00
|
|
|
Usage: docker network create [OPTIONS] NETWORK
|
2016-06-06 08:20:41 -04:00
|
|
|
|
|
|
|
Create a network
|
|
|
|
|
|
|
|
Options:
|
2016-07-16 03:32:17 -04:00
|
|
|
--aux-address value Auxiliary IPv4 or IPv6 addresses used by Network
|
2016-06-06 08:20:41 -04:00
|
|
|
driver (default map[])
|
|
|
|
-d, --driver string Driver to manage the Network (default "bridge")
|
2016-07-16 03:32:17 -04:00
|
|
|
--gateway value IPv4 or IPv6 Gateway for the master subnet (default [])
|
2016-06-06 08:20:41 -04:00
|
|
|
--help Print usage
|
2016-07-16 03:32:17 -04:00
|
|
|
--internal Restrict external access to the network
|
|
|
|
--ip-range value Allocate container ip from a sub-range (default [])
|
2016-06-06 08:20:41 -04:00
|
|
|
--ipam-driver string IP Address Management Driver (default "default")
|
2016-07-16 03:32:17 -04:00
|
|
|
--ipam-opt value Set IPAM driver specific options (default map[])
|
|
|
|
--ipv6 Enable IPv6 networking
|
2016-06-06 08:20:41 -04:00
|
|
|
--label value Set metadata on a network (default [])
|
|
|
|
-o, --opt value Set driver specific options (default map[])
|
2016-07-16 03:32:17 -04:00
|
|
|
--subnet value Subnet in CIDR format that represents a
|
2016-06-06 08:20:41 -04:00
|
|
|
network segment (default [])
|
|
|
|
```
|
2015-09-28 21:57:03 -04:00
|
|
|
|
2015-10-18 19:47:32 -04:00
|
|
|
Creates a new network. The `DRIVER` accepts `bridge` or `overlay` which are the
|
|
|
|
built-in network drivers. If you have installed a third party or your own custom
|
|
|
|
network driver you can specify that `DRIVER` here also. If you don't specify the
|
|
|
|
`--driver` option, the command automatically creates a `bridge` network for you.
|
|
|
|
When you install Docker Engine it creates a `bridge` network automatically. This
|
|
|
|
network corresponds to the `docker0` bridge that Engine has traditionally relied
|
2016-07-01 19:11:01 -04:00
|
|
|
on. When you launch a new container with `docker run` it automatically connects to
|
|
|
|
this bridge network. You cannot remove this default bridge network, but you can
|
2015-10-18 19:47:32 -04:00
|
|
|
create new ones using the `network create` command.
|
2015-09-28 21:57:03 -04:00
|
|
|
|
2015-10-18 19:47:32 -04:00
|
|
|
```bash
|
|
|
|
$ docker network create -d bridge my-bridge-network
|
2015-09-28 21:57:03 -04:00
|
|
|
```
|
2015-10-18 19:47:32 -04:00
|
|
|
|
|
|
|
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
|
2016-07-01 19:11:01 -04:00
|
|
|
Engine, you must create an `overlay` network. Unlike `bridge` networks, overlay
|
2015-10-18 19:47:32 -04:00
|
|
|
networks require some pre-existing conditions before you can create one. These
|
|
|
|
conditions are:
|
|
|
|
|
2015-11-03 08:34:54 -05:00
|
|
|
* Access to a key-value store. Engine supports Consul, Etcd, and ZooKeeper (Distributed store) key-value stores.
|
2015-10-18 19:47:32 -04:00
|
|
|
* A cluster of hosts with connectivity to the key-value store.
|
|
|
|
* A properly configured Engine `daemon` on each host in the cluster.
|
|
|
|
|
2016-06-06 08:20:41 -04:00
|
|
|
The `dockerd` options that support the `overlay` network are:
|
2015-10-18 19:47:32 -04:00
|
|
|
|
|
|
|
* `--cluster-store`
|
|
|
|
* `--cluster-store-opt`
|
|
|
|
* `--cluster-advertise`
|
|
|
|
|
|
|
|
To read more about these options and how to configure them, see ["*Get started
|
2016-10-20 23:24:28 -04:00
|
|
|
with multi-host network*"](https://docs.docker.com/engine/userguide/networking/get-started-overlay).
|
2015-09-30 16:11:36 -04:00
|
|
|
|
2016-07-01 19:11:01 -04:00
|
|
|
While not required, it is a good idea to install Docker Swarm to
|
2015-10-18 19:47:32 -04:00
|
|
|
manage the cluster that makes up your network. Swarm provides sophisticated
|
2016-07-01 19:11:01 -04:00
|
|
|
discovery and server management tools that can assist your implementation.
|
2015-10-18 19:47:32 -04:00
|
|
|
|
|
|
|
Once you have prepared the `overlay` network prerequisites you simply choose a
|
|
|
|
Docker host in the cluster and issue the following to create the network:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ docker network create -d overlay my-multihost-network
|
|
|
|
```
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
## Connect containers
|
|
|
|
|
2016-06-06 19:33:00 -04:00
|
|
|
When you start a container, use the `--network` flag to connect it to a network.
|
2016-07-01 19:11:01 -04:00
|
|
|
This example adds the `busybox` container to the `mynet` network:
|
2015-10-18 19:47:32 -04:00
|
|
|
|
|
|
|
```bash
|
2016-06-06 19:33:00 -04:00
|
|
|
$ docker run -itd --network=mynet busybox
|
2015-09-28 21:57:03 -04:00
|
|
|
```
|
|
|
|
|
2015-10-18 19:47:32 -04:00
|
|
|
If you want to add a container to a network after the container is already
|
2016-07-01 19:11:01 -04:00
|
|
|
running, use the `docker network connect` subcommand.
|
2015-10-18 19:47:32 -04:00
|
|
|
|
|
|
|
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 `overlay` 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.
|
|
|
|
|
|
|
|
You can disconnect a container from a network using the `docker network
|
|
|
|
disconnect` command.
|
|
|
|
|
|
|
|
## Specifying advanced options
|
|
|
|
|
2016-06-06 08:20:41 -04:00
|
|
|
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 `--subnet` option. On a
|
|
|
|
`bridge` network you can only create a single subnet:
|
2015-10-18 19:47:32 -04:00
|
|
|
|
|
|
|
```bash
|
2016-06-06 08:20:41 -04:00
|
|
|
$ docker network create --driver=bridge --subnet=192.168.0.0/16 br0
|
2015-10-18 19:47:32 -04:00
|
|
|
```
|
2016-06-06 08:20:41 -04:00
|
|
|
|
|
|
|
Additionally, you also specify the `--gateway` `--ip-range` and `--aux-address`
|
|
|
|
options.
|
2015-10-18 19:47:32 -04:00
|
|
|
|
|
|
|
```bash
|
2016-06-06 08:20:41 -04:00
|
|
|
$ docker network create \
|
|
|
|
--driver=bridge \
|
|
|
|
--subnet=172.28.0.0/16 \
|
|
|
|
--ip-range=172.28.5.0/24 \
|
|
|
|
--gateway=172.28.5.254 \
|
|
|
|
br0
|
2015-10-18 19:47:32 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
If you omit the `--gateway` flag the Engine selects one for you from inside a
|
|
|
|
preferred pool. For `overlay` networks and for network driver plugins that
|
|
|
|
support it you can create multiple subnetworks.
|
|
|
|
|
|
|
|
```bash
|
2016-06-06 08:20:41 -04:00
|
|
|
$ docker network create -d overlay \
|
|
|
|
--subnet=192.168.0.0/16 \
|
|
|
|
--subnet=192.170.0.0/16 \
|
2016-10-19 13:25:45 -04:00
|
|
|
--gateway=192.168.0.100 \
|
2016-06-06 08:20:41 -04:00
|
|
|
--gateway=192.170.0.100 \
|
|
|
|
--ip-range=192.168.1.0/24 \
|
Fix incorrect aux-address examples and test
The (host)name for aux-addresses should
be unique, otherwise later values overwrite
earlier values.
Before this change, the example command
would send this API request;
{
"Attachable": false,
"CheckDuplicate": true,
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Config": [
{
"Gateway": "192.168.0.100",
"IPRange": "192.168.1.0/24",
"Subnet": "192.168.0.0/16"
},
{
"AuxiliaryAddresses": {
"a": "192.170.1.5",
"b": "192.170.1.6"
},
"Gateway": "192.170.0.100",
"Subnet": "192.170.0.0/16"
}
],
"Driver": "default",
"Options": {
}
},
"Internal": false,
"Labels": {
},
"Name": "my-multihost-network",
"Options": {
}
}
After this change, the request looks
like this (all aux-addresses preserved);
{
"Attachable": false,
"CheckDuplicate": true,
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Config": [
{
"AuxiliaryAddresses": {
"my-router": "192.168.1.5",
"my-switch": "192.168.1.6"
},
"Gateway": "192.168.0.100",
"IPRange": "192.168.1.0/24",
"Subnet": "192.168.0.0/16"
},
{
"AuxiliaryAddresses": {
"my-printer": "192.170.1.5",
"my-nas": "192.170.1.6"
},
"Gateway": "192.170.0.100",
"Subnet": "192.170.0.0/16"
}
],
"Driver": "default",
"Options": {
}
},
"Internal": false,
"Labels": {
},
"Name": "my-multihost-network",
"Options": {
}
}
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2016-09-26 19:02:57 -04:00
|
|
|
--aux-address="my-router=192.168.1.5" --aux-address="my-switch=192.168.1.6" \
|
|
|
|
--aux-address="my-printer=192.170.1.5" --aux-address="my-nas=192.170.1.6" \
|
2015-12-01 00:33:55 -05:00
|
|
|
my-multihost-network
|
2015-10-18 19:47:32 -04:00
|
|
|
```
|
2016-06-06 08:20:41 -04:00
|
|
|
|
|
|
|
Be sure that your subnetworks do not overlap. If they do, the network create
|
|
|
|
fails and Engine returns an error.
|
2015-09-28 21:57:03 -04:00
|
|
|
|
2016-01-18 00:02:10 -05:00
|
|
|
# Bridge driver options
|
|
|
|
|
2016-06-06 08:20:41 -04:00
|
|
|
When creating a custom network, the default network driver (i.e. `bridge`) has
|
|
|
|
additional options that can be passed. The following are those options and the
|
|
|
|
equivalent docker daemon flags used for docker0 bridge:
|
2016-01-18 00:02:10 -05:00
|
|
|
|
|
|
|
| Option | Equivalent | Description |
|
|
|
|
|--------------------------------------------------|-------------|-------------------------------------------------------|
|
|
|
|
| `com.docker.network.bridge.name` | - | bridge name to be used when creating the Linux bridge |
|
|
|
|
| `com.docker.network.bridge.enable_ip_masquerade` | `--ip-masq` | Enable IP masquerading |
|
|
|
|
| `com.docker.network.bridge.enable_icc` | `--icc` | Enable or Disable Inter Container Connectivity |
|
|
|
|
| `com.docker.network.bridge.host_binding_ipv4` | `--ip` | Default IP when binding container ports |
|
2016-09-02 18:39:22 -04:00
|
|
|
| `com.docker.network.driver.mtu` | `--mtu` | Set the containers network MTU |
|
2016-02-11 20:42:15 -05:00
|
|
|
|
2016-06-06 08:20:41 -04:00
|
|
|
The following arguments can be passed to `docker network create` for any
|
|
|
|
network driver, again with their approximate equivalents to `docker daemon`.
|
2016-02-23 11:08:09 -05:00
|
|
|
|
|
|
|
| Argument | Equivalent | Description |
|
|
|
|
|--------------|----------------|--------------------------------------------|
|
2016-07-16 03:32:17 -04:00
|
|
|
| `--gateway` | - | IPv4 or IPv6 Gateway for the master subnet |
|
2016-02-23 11:08:09 -05:00
|
|
|
| `--ip-range` | `--fixed-cidr` | Allocate IPs from a range |
|
2016-07-16 03:32:17 -04:00
|
|
|
| `--internal` | - | Restrict external access to the network |
|
2016-02-23 11:08:09 -05:00
|
|
|
| `--ipv6` | `--ipv6` | Enable IPv6 networking |
|
|
|
|
| `--subnet` | `--bip` | Subnet for network |
|
2016-01-18 00:02:10 -05:00
|
|
|
|
2016-06-06 08:20:41 -04:00
|
|
|
For example, let's use `-o` or `--opt` options to specify an IP address binding
|
|
|
|
when publishing ports:
|
2016-01-18 00:02:10 -05:00
|
|
|
|
|
|
|
```bash
|
2016-06-06 08:20:41 -04:00
|
|
|
$ docker network create \
|
|
|
|
-o "com.docker.network.bridge.host_binding_ipv4"="172.19.0.1" \
|
|
|
|
simple-network
|
2016-01-18 00:02:10 -05:00
|
|
|
```
|
|
|
|
|
2015-12-27 21:15:50 -05:00
|
|
|
### Network internal mode
|
|
|
|
|
2016-06-06 08:20:41 -04:00
|
|
|
By default, when you connect a container to an `overlay` network, Docker also
|
|
|
|
connects a bridge network to it to provide external connectivity. If you want
|
|
|
|
to create an externally isolated `overlay` network, you can specify the
|
|
|
|
`--internal` option.
|
2015-12-27 21:15:50 -05:00
|
|
|
|
2015-10-18 19:47:32 -04:00
|
|
|
## Related information
|
2015-09-28 21:57:03 -04:00
|
|
|
|
2015-10-18 19:47:32 -04:00
|
|
|
* [network inspect](network_inspect.md)
|
|
|
|
* [network connect](network_connect.md)
|
|
|
|
* [network disconnect](network_disconnect.md)
|
|
|
|
* [network ls](network_ls.md)
|
|
|
|
* [network rm](network_rm.md)
|
2016-10-18 00:36:52 -04:00
|
|
|
* [network prune](network_prune.md)
|
2016-10-20 23:24:28 -04:00
|
|
|
* [Understand Docker container networks](https://docs.docker.com/engine/userguide/networking/)
|