Multiple container networks
Creating multiple container networks is possible by using either an external switch, as in transparent, L2 bridge or L2 tunnel networking mode, or by using NAT mode. In NAT mode, multiple container networks are possible on a single container host using logical partitions.
The following command shows the InternalIPAddressPrefix
which can be used to create two or more logical NAT networks falling under the same IP prefix:
get-netnat
As shown in the following screenshot, the InternalIPAddressPrefix
of the container host is 172.20.80.1/20
:
Run the following command to create two NAT networks and a gateway:
docker network create -d nat --subnet 172.20.81.0/24 --gateway 172.20.81.1 natnetwork1 docker network create -d nat --subnet 172.20.82.0/24 --gateway 172.20.82.1 natnetwork2
While creating containers in any subnet, the appropriate network can be chosen using the -network
flag.