Docker Network Create - Docker Docs
Docker Network Create - Docker Docs
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 Docker 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.
Bridge networks are isolated networks on a single Docker Engine installation. If you want to create a
network that spans multiple Docker hosts each running Docker Engine, you must enable Swarm
mode, and create an overlay network. To read more about overlay networks with Swarm mode,
see "use overlay networks".
Once you have enabled swarm mode, you can create a swarm-scoped overlay network:
Ask AI
https://docs.docker.com/reference/cli/docker/network/create/ 1/8
7/11/24, 4:07 PM docker network create | Docker Docs
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.
The --attachable 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.
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.
Options
Option Default Description
--config-from API 1.30+ The network from which to copy the configuration
https://docs.docker.com/reference/cli/docker/network/create/ 2/8
7/11/24, 4:07 PM docker network create | Docker Docs
Examples
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:
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 daemons can also communicate in this way.
You can disconnect a container from a network using the docker network disconnect command.
https://docs.docker.com/reference/cli/docker/network/create/ 3/8
7/11/24, 4:07 PM docker network create | Docker Docs
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:
Additionally, you also specify the --gateway --ip-range and --aux-address options.
If you omit the --gateway flag, Docker 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. This example uses two /25 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.
Be sure that your subnetworks do not overlap. If they do, the network create fails and Docker Engine
returns an error.
https://docs.docker.com/reference/cli/docker/network/create/ 4/8
7/11/24, 4:07 PM docker network create | Docker Docs
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:
The following arguments can be passed to docker network create for any network driver, again
with their approximate equivalents to Docker daemon flags used for the docker0 bridge:
For example, let's use -o or --opt options to specify an IP address binding when publishing
ports:
simple-network
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.
https://docs.docker.com/reference/cli/docker/network/create/ 6/8
7/11/24, 4:07 PM docker network create | Docker Docs
busybox top
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.
Product offerings
Pricing
About us
https://docs.docker.com/reference/cli/docker/network/create/ 7/8
7/11/24, 4:07 PM docker network create | Docker Docs
Support
Contribute
https://docs.docker.com/reference/cli/docker/network/create/ 8/8