As of Docker 18.09 it’s possible to configure swarm to create all networks within given subnets.
Bridge Networks
To configure the default bridge and docker_gwbridge networks, add a list of default address pools to /etc/docker/daemon.json:
{
"default-address-pools": [{"base":"172.80.0.0/16","size":24}]
}
Overlay Networks
For the swarm overlay networks created for Replicated and vendor applications, modify the swarm-init Replicated install script. Find the line with the command docker swarm init and add the --default-addr-pool and --default-addr-pool-mask-length flags. The subnet must not conflict with the one set in /etc/docker/daemon.json.
docker swarm init --advertise-addr="$SWARM_ADVERTISE_ADDR" --listen-addr="$SWARM_LISTEN_ADDR" --default-addr-pool 172.81.0.0/16 --default-addr-pool-mask-length 24