Change default subnet for custom docker networks
Our internal network has a range of 172.20.0.0/16 reserved for internal purposes, and docker uses a default range of 172 for its internal network. I can reset the bridge live to 192.168 by providing bip
for the daemon:
➜ ~ sudo cat /etc/docker/daemon.json
{
"bip": "192.168.2.1/24"
}
➜ ~ ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.2.1 netmask 255.255.255.0 broadcast 0.0.0.0
However, when creating new custom networks through docker network create
or by defining them in sections, networks
docker-compose.yaml
they are still created in 172, which ultimately conflicts with 172.20
:
➜ ~ docker network create foo
610fd0b7ccde621f87d40f8bcbed1699b22788b70a75223264bb14f7e63f5a87
➜ ~ docker network inspect foo | grep Subnet
"Subnet": "172.17.0.0/16",
➜ ~ docker network create foo1
d897eab31b2c558517df7fb096fab4af9a4282c286fc9b6bb022be7382d8b4e7
➜ ~ docker network inspect foo1 | grep Subnet
"Subnet": "172.18.0.0/16",
I understand that I can provide a subnet value docker network create
, but I want all such subnets to be created in 192.168.*
.
How to set up dockerd
for this automatically?
source to share
I just found out that according to the following (still open) pull request this is still not possible: https://github.com/moby/moby/pull/29376
I'll be more than happy to delete this "answer" if you guys know better.
source to share