Docker uses by default /16 network for every network you create with it. This means you have 65534 available IPs in this network. Especially if you use docker-compose, you will create a network for every project / docker-compose file you run.
If you create to many networks, docker will use ip addresses from 192.168.0.0/16 or from 10.0.0.0/8. The chance this interference with your given network is then high. So you should think about the needed network size and adjust the default settings.
Because I mostly did not run many containers, but many projects and so many networks, I use a /27 network for every network. This means I have 30 available IPs. Because I typically have not more than 10 containers in one network, this is enough. You can also choose another network size depending on your needs:
Network Size | IPs | available IPs |
---|---|---|
/27 | 32 | 30 |
/26 | 64 | 62 |
/25 | 128 | 126 |
/24 | 256 | 254 |
Now change your docker default config in /etc/docker/daemon.json
. You have to create the file, if it didn’t exists. And add the setting default-address-pools
:
{ "default-address-pools":[ { "scope": "local", "base":"172.17.0.0/16", "size":27 } ] }
You can choose as base everything you want, but please use only IPs reserved for private networks.