devplayer0 / docker-net-dhcp

Docker network driver for networking on a host bridge with DHCP-allocated IP addresses
GNU General Public License v3.0
202 stars 55 forks source link

Unable to create more than one network of this type. #18

Closed zackzane closed 3 years ago

zackzane commented 3 years ago

Currently, I have several linux bridges configured in my centos installation, configured as such:

3: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff inet 10.1.0.254/24 brd 10.1.0.255 scope global br0 valid_lft forever preferred_lft forever 4: br1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:13:95:27:b1:4d brd ff:ff:ff:ff:ff:ff inet 192.168.1.120/24 brd 192.168.1.255 scope global dynamic br1 valid_lft 77484sec preferred_lft 77484sec

In this case, br0 is not attached to any external network devices, but instead we have dnsmasq running to provide dhcp services for br0. br1 is bridged to eth0 which is an external device connected to my router which obviously provides dhcp services for eth0 (any any interfaces connected to br1).

The error I get is "Error response from daemon: NetworkDriver.CreateNetwork: bridge already in use by Docker" However as far as I can tell, docker is not using either of those bridges for anything else.

I can create a docker 'dhcp' network just fine by using either of those bridges. However once I have created a network using one of those bridges, I can't create another network using the other bridge. My end goal is to be able to create a network for each bridge, and attached each network to a running container so it would have 2 network interfaces - each connected to one of the above bridges, and with IP addresses issued via dhcp from each of those bridges.

Is this possible to do? Or is there some technical reason why we won't be able to create two separate docker networks of this type?

Thanks.

devplayer0 commented 3 years ago

I haven't tested this but it should be possible, so long as you don't create more than one network using the same bridge. It's possible there's a bug somewhere when checking for this.

devplayer0 commented 3 years ago

I believe this is due to Docker networks with the null IPAM driver (e.g. those using this plugin!) end up with the subnet 0.0.0.0/0 so any bridges that have an IP address at network creation time fail this check. If you create the network before assigning IP addresses to the bridges it should succeed (as a workaround). I'll have this check look out for the null IPAM driver.

zackzane commented 3 years ago

I can confirm that the workaround does indeed work. Much appreciated! With whatever update you make, do you think that this workaround will generally be the way to do this going forward?

devplayer0 commented 3 years ago

20 should fix this (workaround no longer required). I've also added an option ignore_conflicts to disable the check if all else fails!