Bite-Sized Dev Tips

Bite-Sized Dev Tips

The goal is to help you, the developer, by turning complex things into understandable, bite-sized pieces.

Docker - Too many bridged networks

How to solve the 'too many bridged networks' Docker error

Geoff Safcik

2-Minute Read

Docker - Too many networks

NOTE: this post will be more for Docker Desktop for Mac but this is applicable across devices.

Docker networking…

Some people love it, some loathe it.

Today is all about the problem where Docker cannot find an available IP address to assign to its bridged network. You’ll see an error like this:

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

Let’s dive a little bit deeper, remembering that this blog tries to keep things in “bite-sized pieces”.

Why does this happen?

Docker has a limit for bridged networks (31 by default). That’s it.

How to solve

Extra bridge networks not in use

If you have extra bridge networks not in use…prune them with:

$ docker network prune
WARNING! This will remove all networks not used by at least one container.
Are you sure you want to continue? [y/N]

Type y and press enter and you’re good to go (after it runs…).

NO extra bridge networks not in use

Sometimes, you just max out the bridge networks! Here’s a nice answer from SO by Another Code (credit where credit is due!):

Since Docker version 18.06 the allocation ranges can be customized in the daemon configuration like so:

/etc/docker/daemon.json

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

This example would create a pool of /24 subnets out of a /16 range, increasing the bridge network limit from 31 to 255. More pools could be added as necessary. Note that this limits the number of attached containers per network to about 254.

Although I haven’t needed to do this in any real capacity (yet), I thought I’d point you to this answer. This setting is indeed in the Docker docs, the answer makes complete sense, and looks completely valid. So, if you’ve done this before, let me know if it worked for you!

Well, that’s where we’ll leave it to keep it “bite-sized”. Hope this helps someone 😉

comments powered by Disqus

Recent Posts

categories