basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    Docker’s subnet clashed with the home network — set default-address-pools

    Docker takes subnets for user-defined networks in order: fifteen /16s from 172.17–172.31, then /20 chunks of 192.168.0.0/16, where home and office networks usually live. Once a subnet matches the network the server is reached from, replies to those machines go into the Docker bridge. Set the pool yourself in daemon.json while there are still few networks.

    Where Docker gets subnets from

    172.17.0.0/16                   default bridge network, docker0
    172.18.0.0/16 … 172.31.0.0/16   14 more networks
    192.168.0.0/20                  16th network: 192.168.0.x … 192.168.15.x
    192.168.16.0/20 …               and onward in chunks of 16 /24 subnets

    Every compose stack creates at least one network, <project>_default, and a stack with a database usually has two. Together with the shared proxy, the fifteenth user-defined network shows up as early as the seventh or eighth stack with a database, and it gets 192.168.0.0/20 — which covers the office network 192.168.10.0/24. Later chunks reach the router’s guest network 192.168.89.0/24 too (Guest network on MikroTik). For the server, that subnet is now local: a reply to an address in it goes into the br-… bridge instead of to the gateway, and the client sees a hung connection.

    How to set your own pool

    Add the key to /etc/docker/daemon.json — next to the log limit from Docker on Ubuntu, and don’t forget the comma after the previous key:

      "default-address-pools": [
        { "base": "172.20.0.0/14", "size": 24 }
      ]

    172.20.0.0/14 is 172.20.0.0–172.23.255.255: homes and offices use 172.16.0.0/12 less often than 192.168 and 10. size: 24 gives each network a /24, 254 addresses: plenty for a stack, and the pool holds 1024 networks. If a network on your path to the server is in 172.20–172.23, take another piece of 172.16.0.0/12.

    sudo dockerd --validate --config-file /etc/docker/daemon.json
    # configuration OK
    sudo systemctl restart docker

    systemctl restart docker restarts every container — do it at a quiet time.

    The pool applies only to new networks: existing ones keep their subnet. Recreate a stack’s network with docker compose down && docker compose up -d in its directory. Docker removes a shared network like proxy only when no containers are left on it: stop the stacks on it, then docker network rm proxy && docker network create proxy, and bring the stacks back up.

    If it doesn’t work

    Another stack came up, and SSH to the server from the office or a neighboring home network hangs

    Cause
    The new Docker network got a subnet containing the client’s address: the server’s reply went into the Docker bridge instead of to the gateway.
    Fix
    Run ip route on the server and look for a line like 192.168.…/20 dev br-…. Set default-address-pools and recreate that network.

    A device on the home network doesn’t open from a container, but opens from the host

    Cause
    The container’s network took the same subnet: to the container that address is a neighbor on the bridge, and the packet never reaches the router.
    Fix
    The same pool in daemon.json, then recreate the container’s network.

    could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network

    Cause
    The default pools ran out: they hold 31 subnets, and the server already has that many networks.
    Fix
    default-address-pools with size: 24 — the pool then holds over a thousand networks. docker network prune removes unused networks, but proxy goes with them if every stack on it is stopped right now.

    How to check

    The subnets of every network on the server:

    docker network ls -q --filter driver=bridge | xargs docker network inspect --format '{{.Name}} {{range .IPAM.Config}}{{.Subnet}}{{end}}'
    # bridge 172.17.0.0/16
    # proxy 172.20.0.0/24
    # umami_internal 172.20.1.0/24

    A new network gets a /24 from your pool:

    docker network create pooltest
    docker network inspect pooltest --format '{{range .IPAM.Config}}{{.Subnet}}{{end}}'
    docker network rm pooltest

    From the machine that lost the server — ssh web1 again.