Docker – Configuring Docker to Avoid Using 172.17.0.0 Range

dockerdocker-compose

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)?

Best Answer

It is possible to redefine default range.

$ docker -v
Docker version 18.06.0-ce, build 0ffa825

Edit or create config file for docker daemon:

# nano /etc/docker/daemon.json

Add lines:

{
  "default-address-pools":
  [
    {"base":"10.10.0.0/16","size":24}
  ]
}

Restart dockerd:

# service docker restart

Check the result:

$ docker network create foo
$ docker network inspect foo | grep Subnet
                    "Subnet": "10.10.1.0/24"

It works for docker-compose too. More info here https://github.com/moby/moby/pull/29376 (merged)

Related Topic