2 min read

Change Default Docker Subnet 172.17.0.0/16

By default, Docker utilizes the 172.17.0.0/16 subnet, which conflicts with my current cloud network. To resolve this issue, it is necessary to instruct Docker to use an alternative subnet.

The following three blocks are reserved for private networks, and Docker often uses one of them:

  • 10.0.0.0 to 10.255.255.255 (10.0.0.0/8)

    This is a large private IP address range suitable for larger deployments.

  • 172.17.0.0 to 172.31.255.255 (172.17.0.0/12)

    This is the default Docker bridge network range.

  • 192.168.0.0 to 192.168.255.255 (192.168.0.0/16)

    This is another commonly used private IP address range.

I prefer to choose 10.0.0.0/24 for my server due to its small nodes. Simply create a file at /etc/docker/daemon.json or merge this configuration with existing values if the file already exists.

/etc/docker/daemon.json
{
  "default-address-pools": [
    {
      "base": "10.0.0.0/24",
      "size": 24
    }
  ]
}

Afterward, restart the Docker service by executing service docker restart.

You can verify the subnet in use by running ip route show

$ ip route show
default via 172.17.254.251 dev ens160 proto static
10.0.0.0/24 dev docker0 proto kernel scope link src 10.0.0.1
172.17.254.0/24 dev ens160 proto kernel scope link src 172.17.254.117
172.19.0.0/16 dev br-fbd8b5f416d2 proto kernel scope link src 172.19.0.1 linkdown
172.20.0.0/16 dev br-b97047047f76 proto kernel scope link src 172.20.0.1 linkdown

It is worth noting that specific routes can be removed using the command ip route del [line]. For example,

ip route del 10.0.0.0/24 dev docker0 proto kernel scope link src 10.0.0.1