.nh .TH "DOCKER" "1" "May 2024" "Docker Community" "Docker User Manuals" .SH NAME .PP docker-network-create - Create a network .SH SYNOPSIS .PP \fBdocker network create [OPTIONS] NETWORK\fP .SH DESCRIPTION .PP Creates a new network. The \fBDRIVER\fR accepts \fBbridge\fR or \fBoverlay\fR which are the built-in network drivers. If you have installed a third party or your own custom network driver you can specify that \fBDRIVER\fR here also. If you don't specify the \fB--driver\fR option, the command automatically creates a \fBbridge\fR network for you. When you install Docker Engine it creates a \fBbridge\fR network automatically. This network corresponds to the \fBdocker0\fR bridge that Engine has traditionally relied on. When you launch a new container with \fBdocker run\fR it automatically connects to this bridge network. You cannot remove this default bridge network, but you can create new ones using the \fBnetwork create\fR command. .EX $ docker network create -d bridge my-bridge-network .EE .PP 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 enable Swarm mode, and create an \fBoverlay\fR network. To read more about overlay networks with Swarm mode, see " \[la]https://docs.docker.com/network/overlay/\[ra]\&. .PP Once you have enabled swarm mode, you can create a swarm-scoped overlay network: .EX $ docker network create --scope=swarm --attachable -d overlay my-multihost-network .EE .PP By default, swarm-scoped networks do not allow manually started containers to be attached. This restriction is added to prevent someone that has access to a non-manager node in the swarm cluster from running a container that is able to access the network stack of a swarm service. .PP The \fB--attachable\fR option used in the example above disables this restriction, and allows for both swarm services and manually started containers to attach to the overlay network. .PP 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. .SS Overlay network limitations .PP You should create overlay networks with \fB/24\fR blocks (the default), which limits you to 256 IP addresses, when you create networks using the default VIP-based endpoint-mode. This recommendation addresses limitations with swarm mode \[la]https://github.com/moby/moby/issues/30820\[ra]\&. If you need more than 256 IP addresses, do not increase the IP block size. You can either use \fBdnsrr\fR endpoint mode with an external load balancer, or use multiple smaller overlay networks. See Configure service discovery \[la]https://docs.docker.com/engine/swarm/networking/#configure\-service\-discovery\[ra] for more information about different endpoint modes. .SH Connect containers .PP When you start a container, use the \fB--network\fR flag to connect it to a network. This example adds the \fBbusybox\fR container to the \fBmynet\fR network: .EX $ docker run -itd --network=mynet busybox .EE .PP If you want to add a container to a network after the container is already running, use the \fBdocker network connect\fR subcommand. .PP 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 \fBoverlay\fR 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. .PP You can disconnect a container from a network using the \fBdocker network disconnect\fR command. .SS Specify advanced options .PP 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 \fB--subnet\fR option. On a \fBbridge\fR network you can only create a single subnet: .EX $ docker network create --driver=bridge --subnet=192.168.0.0/16 br0 .EE .PP Additionally, you also specify the \fB--gateway\fR \fB--ip-range\fR and \fB--aux-address\fR options. .EX $ docker network create \\ --driver=bridge \\ --subnet=172.28.0.0/16 \\ --ip-range=172.28.5.0/24 \\ --gateway=172.28.5.254 \\ br0 .EE .PP If you omit the \fB--gateway\fR flag the Engine selects one for you from inside a preferred pool. For \fBoverlay\fR networks and for network driver plugins that support it you can create multiple subnetworks. This example uses two \fB/25\fR 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. .EX $ 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 .EE .PP Be sure that your subnetworks do not overlap. If they do, the network create fails and Engine returns an error. .SS Bridge driver options .PP When creating a custom network, the default network driver (i.e. \fBbridge\fR) has additional options that can be passed. The following are those options and the equivalent docker daemon flags used for docker0 bridge: .TS allbox; l l l l l l . \fBOption\fP \fBEquivalent\fP \fBDescription\fP \fBcom.docker.network.bridge.name\fR - T{ Bridge name to be used when creating the Linux bridge T} \fBcom.docker.network.bridge.enable_ip_masquerade\fR \fB--ip-masq\fR Enable IP masquerading \fBcom.docker.network.bridge.enable_icc\fR \fB--icc\fR T{ Enable or Disable Inter Container Connectivity T} \fBcom.docker.network.bridge.host_binding_ipv4\fR \fB--ip\fR T{ Default IP when binding container ports T} \fBcom.docker.network.driver.mtu\fR \fB--mtu\fR Set the containers network MTU \fBcom.docker.network.container_iface_prefix\fR - T{ Set a custom prefix for container interfaces T} .TE .PP The following arguments can be passed to \fBdocker network create\fR for any network driver, again with their approximate equivalents to \fBdocker daemon\fR\&. .TS allbox; l l l l l l . \fBArgument\fP \fBEquivalent\fP \fBDescription\fP \fB--gateway\fR - T{ IPv4 or IPv6 Gateway for the master subnet T} \fB--ip-range\fR \fB--fixed-cidr\fR Allocate IPs from a range \fB--internal\fR - T{ Restrict external access to the network T} \fB--ipv6\fR \fB--ipv6\fR Enable IPv6 networking \fB--subnet\fR \fB--bip\fR Subnet for network .TE .PP For example, let's use \fB-o\fR or \fB--opt\fR options to specify an IP address binding when publishing ports: .EX $ docker network create \\ -o "com.docker.network.bridge.host_binding_ipv4"="172.19.0.1" \\ simple-network .EE .SS Network internal mode .PP By default, when you connect a container to an \fBoverlay\fR network, Docker also connects a bridge network to it to provide external connectivity. If you want to create an externally isolated \fBoverlay\fR network, you can specify the \fB--internal\fR option. .SS Network ingress mode .PP You can create the network which will be used to provide the routing-mesh in the swarm cluster. You do so by specifying \fB--ingress\fR 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 \fB--attachable\fR option. .EX $ 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 .EE .SS Run services on predefined networks .PP You can create services on the predefined docker networks \fBbridge\fR and \fBhost\fR\&. .EX $ docker service create --name my-service \\ --network host \\ --replicas 2 \\ busybox top .EE .SS Swarm networks with local scope drivers .PP You can create a swarm network with local scope network drivers. You do so by promoting the network scope to \fBswarm\fR during the creation of the network. You will then be able to use this network when creating services. .EX $ docker network create -d bridge \\ --scope swarm \\ --attachable \\ swarm-network .EE .PP For network drivers which provide connectivity across hosts (ex. macvlan), if node specific configurations are needed in order to plumb the network on each host, you will supply that configuration via a configuration only network. When you create the swarm scoped network, you will then specify the name of the network which contains the configuration. .EX node1$ docker network create --config-only --subnet 192.168.100.0/24 --gateway 192.168.100.115 mv-config node2$ docker network create --config-only --subnet 192.168.200.0/24 --gateway 192.168.200.202 mv-config node1$ docker network create -d macvlan --scope swarm --config-from mv-config --attachable swarm-network .EE .SH OPTIONS .PP \fB--attachable\fP[=false] Enable manual container attachment .PP \fB--aux-address\fP=map[] Auxiliary IPv4 or IPv6 addresses used by Network driver .PP \fB--config-from\fP="" The network from which to copy the configuration .PP \fB--config-only\fP[=false] Create a configuration only network .PP \fB-d\fP, \fB--driver\fP="bridge" Driver to manage the Network .PP \fB--gateway\fP=[] IPv4 or IPv6 Gateway for the master subnet .PP \fB-h\fP, \fB--help\fP[=false] help for create .PP \fB--ingress\fP[=false] Create swarm routing-mesh network .PP \fB--internal\fP[=false] Restrict external access to the network .PP \fB--ip-range\fP=[] Allocate container ip from a sub-range .PP \fB--ipam-driver\fP="default" IP Address Management Driver .PP \fB--ipam-opt\fP=map[] Set IPAM driver specific options .PP \fB--ipv6\fP[=false] Enable IPv6 networking .PP \fB--label\fP= Set metadata on a network .PP \fB-o\fP, \fB--opt\fP=map[] Set driver specific options .PP \fB--scope\fP="" Control the network's scope .PP \fB--subnet\fP=[] Subnet in CIDR format that represents a network segment .SH SEE ALSO .PP \fBdocker-network(1)\fP