Docker Community Forums

Share and learn in the Docker community.

Influence what subnets are used for docker networks


(Bkraul) #1

I am trying to figure out how to make sure docker does not use certain subnets in the creation of container networks in a linux docker environment.

I know there is this:

https://success.docker.com/article/how-do-i-influence-which-network-address-ranges-docker-chooses-during-a-docker-network-create

But interestingly enough it does not say how to actually make that happen in terms of the commands. I am sure it assumes the reader already knows what those commands are, but it is not always the case, as with me.

Would anyone be so kind as to help me out?

I am trying to make sure all bridged networks stay within the 172.* range.


(Bkraul) #2

I hate it when people find answers and don’t contribute to the good of others. So, after looking around, here is what I found.

I use Ubuntu 18.04, which uses netplans instead of /etc/network/interfaces.

Using route add (which does not survive reboots), if you wanted to make sure docker does not use any 192.168.* addresses for creating networks, you would do something like:

route add -net 192.168.0.0/16 gw [your gateway ip] dev [your network device, i.e. eth0]

Using netplan, you would add this to /etc/netplan/01-netcfg.yaml (under the proper device, at the same level as gateway and nameservers):

      routes:
        - to: 192.168.0.0/16
          via: [your gateway ip]

And then execute netplan apply

After that, you can kill any containers using networks with IPs you don’t want, and recreate them.


(Tnelis) #3

This is now configurable:

There was a proposal to change the default to something less commonly used in LANs but this was rejected.