Docker Can Only Create 31 Default Networks

I have just learned that Docker has a limit of 31 networks for a default bridge network driver on a single machine:

~$ docker network create test1
289c3909adbc9f79cdc7ce640d66904088cdff72fbf611cdd124c9681aa0a0e7
~$ docker network create test2
567eb19074ba8d76df7f6b65887a3e75117b0cb748afaa5f3bfe3a750ff9f627
...
~$ docker network create test31
f4ec74b0f34b7f7961676e48e53abbf4f5394e18f6a750f98f43091cb2f0d0dd
~$ docker network create test32
Error response from daemon: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network

This is due to the fact that it uses a hardcoded list of broad network ranges for a bridge network driver: 172.17-31.x.x/16 and 192.168.x.x/20. For an overlay network driver, 64K networks can be created. If you want to know the implementation details, please look into Docker libnetwork’s ipamutils and allocator.

The only solution to circumvent this limitation seems to be manually specifying subnet ranges for each created network (please see Docker network create subnet option and Docker Compose network configuration reference):

docker network create --subnet=192.168.1.0/24 test1

In Puffin, which needs to create a separate network for each application, I implemented a simple address allocator.


Originally published at loomchild.net on September 4, 2016.