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

No, but this is not what happens. If it did, none of your containers could communicate with eachother. Docker Compose creates a new network by default for each compose project. If you just test some compose project and don’t remove them, the network will stay there and eventually there will be no available network as all the IP ranges are used. If you have unused projects, remove them by running docker compose down in the project directory or remove the unused networks manually. You can also run docker network prune if the project directories are allready removed and want to remove all unused networks if the containers were removed as well.

If you really need lots of Docker compose projects, you have to customize the default address pool.

Quote from the example daemon.json:

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

That would create two pools. One pool defines IP range of the pool with the network ip and the mask size of each network that can be created in the pool automatically. In the example it means the first pool can start with 172.30.0.0 and end with 172.30.255.255 and the second pool can start with 172.31.0.0 and end with 172.31.255.255. Since the size is 24, it means the first network in the first pool would be “172.30.1.0/24”, the second network would be “172.30.2.0/24” and so on. The default IP range is wide and allows roughly 65536 ip addresses in a single compose network, but the docker networks wer not created for compose specifically and you could need a large network in a large system where every container is on the same network. So it is just a very big network range that would be hard to run out of.

The best if you know exactly how many container you need in a compose project and configure the default network in that project to use a specific subnet like this:

networks:
  default:
    ipam:
      driver: default
      config:
        - subnet: 172.42.12.0/29
          gateway: 172.42.12.1

services:
  web:
    image: httpd:2.4

This allows 8 IP addresses in the subnet, but the first is the network IP, the second is the gateway, the last is the broadcast ip, so you have 8-3 = 5 free IP addresses for containers.

Your next compose project could be

networks:
  default:
    ipam:
      driver: default
      config:
        - subnet: 172.42.12.8/29
          gateway: 172.42.12.9

services:
  web:
    image: httpd:2.4

so now your project can use container IP addresses from 172.42.12.10 to 172.42.12.14.

I used 172.42.12 as an example, but it can be anything from the private ip ranges:

2 Likes