Due to problems with captive portals and the default Docker IP range I am trying to make Docker use the 198.18.0.0 range, instead of 172.17.0.0, which clashes with the captive portals used on the trains where I live.
Following the docs, I created /etc/docker/daemon.json, and put the following in it:
{
"bip":"198.18.0.0/16"
}
This worked for docker0, but it seems to not have affected any of the other networks, and using docker compose the first network created is 172.17.0.0, which recreates the clash.
What can I do to change the default subnet for all docker networks (preferably without having to state my custom IP range in every compose file)?
There are three places docker will generate network subnets.
The default bridge
User generated bridge networks
Swarm mode generated overlay networks
For the default bridge (called "bridge"), you can specify BIP (I believe that's Bridge IP; make sure it's a host IP, not a network IP) in the daemon.json file. And for user generated bridge networks you can define a subnet pool to pick from (assuming the user does not manually specify a subnet). For these two, your /etc/docker/daemon.json would look like:
Each address pool setting above defines a CIDR range and size of subnets to be allocated from that range. So the above defines two class B ranges that are allocated as class C networks (/24). You do need at least 18.06 for the default address pools. You will need to reload the docker daemon for this change to apply (systemctl reload docker). And this change will only modify newly created user networks, so you'll need to stop containers and delete existing networks in the wrong range.
In 18.09, Docker added the ability to specify the address range for swarm mode generated overlay networks. This can only be done at the time of swarm creation right now, hopefully that will be updated in the future to allow docker swarm update to adjust these pools:
Configure the default bridge network:
"… To configure the default bridge network, you specify options in daemon.json. Here is an example daemon.json with several options specified. Only specify the settings you need to customize. …"
With compose: Specify custom networks:
"… Instead of just using the default app network, you can specify your own networks with the top-level networks key. This lets you create more complex topologies and specify custom network drivers and options. You can also use it to connect services to externally-created networks which aren’t managed by Compose. …"