docker network create

Estimated reading time: 8 minutes


Create a network


docker network create [OPTIONS] NETWORK


Name, shorthandDefaultDescription
--attachableAPI 1.25+ 
Enable manual container attachment
--aux-addressAuxiliary IPv4 or IPv6 addresses used by Network driver
--config-fromAPI 1.30+ 
The network from which copying the configuration
--config-onlyAPI 1.30+ 
Create a configuration only network
--driver , -dbridgeDriver to manage the Network
--gatewayIPv4 or IPv6 Gateway for the master subnet
--ingressAPI 1.29+ 
Create swarm routing-mesh network
--internalRestrict external access to the network
--ip-rangeAllocate container ip from a sub-range
--ipam-driverIP Address Management Driver
--ipam-optSet IPAM driver specific options
--ipv6Enable IPv6 networking
--labelSet metadata on a network
--opt , -oSet driver specific options
--scopeAPI 1.30+ 
Control the network’s scope
--subnetSubnet in CIDR format that represents a network segment

Parent command

docker networkManage networks
docker network connectConnect a container to a network
docker network createCreate a network
docker network disconnectDisconnect a container from a network
docker network inspectDisplay detailed information on one or more networks
docker network lsList networks
docker network pruneRemove all unused networks
docker network rmRemove one or more networks

Extended description

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 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 create new ones using the network create command.

$ docker network create -d bridge my-bridge-network

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 overlay network. Unlike bridge networks, overlay networks require some pre-existing conditions before you can create one. These conditions are:

  • Access to a key-value store. Engine supports Consul, Etcd, and ZooKeeper (Distributed store) key-value stores.
  • A cluster of hosts with connectivity to the key-value store.
  • A properly configured Engine daemon on each host in the cluster.

The dockerd options that support the overlay network are:

  • --cluster-store
  • --cluster-store-opt
  • --cluster-advertise

To read more about these options and how to configure them, see Get started with multi-host network.

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.

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:

$ 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

When you start a container, use the --network flag to connect it to a network. This example adds the busybox container to the mynet network:

$ docker run -itd --network=mynet busybox

If you want to add a container to a network after the container is already running, use the docker network connect subcommand.

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.

Specify advanced options

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:

$ docker network create --driver=bridge --subnet= br0

Additionally, you also specify the --gateway --ip-range and --aux-address options.

$ docker network create \
  --driver=bridge \
  --subnet= \
  --ip-range= \
  --gateway= \

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.

$ docker network create -d overlay \
  --subnet= \
  --subnet= \
  --gateway= \
  --gateway= \
  --ip-range= \
  --aux-address="my-router=" --aux-address="my-switch=" \
  --aux-address="my-printer=" --aux-address="my-nas=" \

Be sure that your subnetworks do not overlap. If they do, the network create fails and Engine returns an error.

Bridge driver options

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:

OptionEquivalentDescription name to be used when creating the Linux bridge IP masquerading or Disable Inter Container Connectivity IP when binding container ports the containers network MTU

The following arguments can be passed to docker network create for any network driver, again with their approximate equivalents to docker daemon.

--gateway-IPv4 or IPv6 Gateway for the master subnet
--ip-range--fixed-cidrAllocate IPs from a range
--internal-Restrict external access to the network
--ipv6--ipv6Enable IPv6 networking
--subnet--bipSubnet for network

For example, let’s use -o or --opt options to specify an IP address binding when publishing ports:

$ docker network create \
    -o ""="" \

Network internal mode

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.

Network ingress mode

You can create the network which will be used to provide the routing-mesh in the swarm cluster. You do so by specifying --ingress 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 --attachable option.

$ docker network create -d overlay \
  --subnet= \
  --ingress \
  --opt \
  --opt encrypted=true \