Configure Docker Swarm to use a Subnet


As of Docker 18.09 it’s possible to configure swarm to create all networks within given subnets.

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":"","size":24}]

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 --default-addr-pool-mask-length 24