Karan Sharma

Configuring Custom Subnets in Docker

3 minutes (680 words)

Docker uses as the CIDR for it’s own network and all the other bridge network it creates. It maybe sometimes useful to change the default subnet to a custom one, in case it conflitcts with other resources (like AWS VPC) in your infra. Not just this, it can also happen if you’ve multiple docker-compose projects in your server and you face an error similar to:

ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network
$ ip a show docker0

8: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:18:b7:60:80 brd ff:ff:ff:ff:ff:ff
    inet brd scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:18ff:feb7:6080/64 scope link
       valid_lft forever preferred_lft forever


If you’re using docker-compose, then you can simply update the subnet for the bridge network created in that file by giving custom IPAM options in the network section of the file.

    image: app/app:latest
      - monitor-net

      driver: default
        - subnet:

🔗Docker settings

If you wish to update the base address of docker0 interface and define these subnets globally, you can update daemon.json settings.

Add the following to /etc/docker/daemon.json. Create the file if it doesn’t exist.

  "bip": "",
sudo systemctl restart docker

🔗Verify the settings

ip a show docker0

You should see


  1. "bip": ""

    • bip stands for “Bridge IP”.
    • This specifies the IP address and subnet for the Docker daemon’s default bridge network. The default bridge network is used for communications between the Docker host and containers that do not specify a network.
    • is the IP address assigned to the bridge interface on the Docker host.
    • /24 indicates that the subnet mask is, which means that the IP addresses from to are available for use by containers connected to this bridge.
  2. "default-address-pools": [...]

    • This is an array defining pools of network addresses that Docker can use for creating user-defined networks (i.e., networks created using docker network create).

    Inside the default-address-pools array, we have two objects, each specifying a base subnet and a size for the network pools:

    • {"base":"","size":24}

      • This pool defines a range of IP addresses starting with the base
      • /16 means that any address from to can be used to create smaller subnets.
      • "size":24 specifies that when Docker creates a user-defined network from this pool, it should use a subnet size of /24. Therefore, each user-defined network created from this pool will have a range of IP addresses like 10.201.x.0/24, where x is a variable that increments for each new network, providing 254 usable addresses for each subnet.
    • {"base":"","size":24}

      • Similar to the first pool, but this uses the range.
      • Again, the "size":24 means that Docker will create user-defined networks with a /24 subnet from this range, for example 10.202.x.0/24, where x is an incrementing value.


Tags: #Docker