Increase Docker network

  • I am still learning docker networking so I still need some help.

    I have reached the maximum amount of Docker containers of my host machine and have no free IP addresses for new containers.


    For this I need to add another network to docker and I have found a post about that. I have to edit the /etc/docker/daemon.json file. But obviously it gets reset after a restart of the host machine.

    My question: Do I now have to find a solution to make the above configuration permanent or if I also can create a network myself, how to add it to the default docker networks that docker knows it can use its IP addresses to create new containers.

  • I only have extremely basic experience with Docker networking as well, but three things come to mind:


    1) I don't think you want to manually modify daemon.json to configure networking -- there is a series of commands via docker network  that you should probably execute from shell instead.


    2) All of your running Docker containers are already assigned addresses & subnets -- I don't think manual/forced changes to the network while they're running will end well! In a "best case scenario" they might re-connect to a new network scope after a restart... but if they don't you'll lose IP connectivity to your existing containers.


    3) In what network do you suspect you've expended all available IP leases?(!) For example "bridge" or "host"? By default Docker networks are Class B ranges, which in theory can accommodate 65,534 hosts per network! How many containers are you running? 8| haha

  • 1) I don't think you want to manually modify daemon.json to configure networking -- there is a series of commands via docker network that you should probably execute from shell instead.


    2) All of your running Docker containers are already assigned addresses & subnets -- I don't think manual/forced changes to the network while they're running will end well! In a "best case scenario" they might re-connect to a new network scope after a restart... but if they don't you'll lose IP connectivity to your existing containers.

    Yes true you are right. That is not a good idea to configure it like that in the file. Good that I have not done it yet.


    3) In what network do you suspect you've expended all available IP leases?(!) For example "bridge" or "host"? By default Docker networks are Class B ranges, which in theory can accommodate 65,534 hosts per network! How many containers are you running? 8| haha

    I have around 30 containers and I get the message that there are no available IP addresses left for new containers.

    Based on docker network ls most of my containers are on the bridge network. So I guess that it is full. So I have to create a new one I guess? I would like to know what range the default bridge network is because just 30 IPs available seems very less.

  • Nevermind I do it on the go.


    docker network ls presented me a lot of individuall /16 networks. A lot of my containers have no specific network settings so they will always try to use the default docker network 172.16.0.0/12 and create smaller /16 networks. And I guess the default docker network is out of IP addresses, so I needed to create a new specific network for my new containers. For example a "container31_network" with the range 172.32.0.0/24.


    I think the default network has no space anymore.

  • Question:


    How are you deploying your containers? Compose plug-in, portainer, cli?


    If using the plug-in or portainer stacks, you can use the network commands in the compose files to easily create and attach to different networks. Containers will automatically create and attach to a network on launch. If the network were to get pruned, the network gets re-created on launch.


    I have 30+ containers running but I like to group them on different docker networks based on purpose, using a combination of the network commands and multi container compose files (I use portainer) ie. web accessible stuff is on a “web” network, admin related stuff on an “admin” network, central database related stuff on a “database” network, etc. I don’t do this for ip limits, but more for organization and a little increased isolation of web accessible containers.

  • I should also note that the subnet mask on a network dictates the the number of available up addresses. A /24 network can handle 256 ip addresses (first and last are usually reserved so 254 usable) a /16 network can handle 65534 addresses, so I highly doubt you are running out of ip addresses unless you have been messing with something that has broken the networking.

  • Question:


    How are you deploying your containers? Compose plug-in, portainer, cli?


    If using the plug-in or portainer stacks, you can use the network commands in the compose files to easily create and attach to different networks. Containers will automatically create and attach to a network on launch. If the network were to get pruned, the network gets re-created on launch.


    I have 30+ containers running but I like to group them on different docker networks based on purpose, using a combination of the network commands and multi container compose files (I use portainer) ie. web accessible stuff is on a “web” network, admin related stuff on an “admin” network, central database related stuff on a “database” network, etc. I don’t do this for ip limits, but more for organization and a little increased isolation of web accessible containers.

    Most of my containers are deployed as docker-compose stacks. Yes I have to modify their network and group them up, you are right. I just lacked the reason why to group them. Now I know it 😅. I don't want to reconfigure some containers but I guess I have to. Thanks for your help and knowledge.

    I should also note that the subnet mask on a network dictates the the number of available up addresses. A /24 network can handle 256 ip addresses (first and last are usually reserved so 254 usable) a /16 network can handle 65534 addresses, so I highly doubt you are running out of ip addresses unless you have been messing with something that has broken the networking.

    The reason why I think reconfiguring their network makes sense is because some containers will never use so many IP like in a /16 network, but they block the IP range for other containers. So I think I will create a small network for containers who do not use so many IPs. Previously I was a bit wasting IP range because I never assumed I will have so many containers. Turns out I was wrong and I need them. 😅

  • If the network were to get pruned, the network gets re-created on launch.

    One question related to docker network prune. You said if I prune a network, by accident it gets recreated after restart. Will the configuration also be recreated, or is the container done, and I have to reconfigure it. Because once I have accidentally pruned my nextcloud network and everything was messed up. I had to reconfigure it.

  • Zitat


    The reason why I think reconfiguring their network makes sense is because some containers will never use so many IP like in a /16 network, but they block the IP range for other containers. So I think I will create a small network for containers who do not use so many IPs. Previously I was a bit wasting IP range because I never assumed I will have so many containers. Turns out I was wrong and I need them. 😅


    You are getting too focused on the whole ip address thing. There is no need to go carving up the docker networks into smaller ranges. A container will not block another container from using available Ip addresses on a given network.


    There are really only two things you have to worry about with docker networks:

    1) What is the network name and what containers do you have on it

    2) Does a container require a LAN ip instead of a docker ip (Things like a pihole container require this and as such need to be attached to a macvlan)




    Zitat


    One question related to docker network prune. You said if I prune a network, by accident it gets recreated after restart. Will the configuration also be recreated, or is the container done, and I have to reconfigure it. Because once I have accidentally pruned my nextcloud network and everything was messed up. I had to reconfigure it.

    When networks are declared in a compose file, they get created when the compose file is run by docker. This will download what the container needs if is isn't already on your system and then create and deploy the container and in this case the network too. The container will always have the same name and always be created as long as the container is running.


    Pruning will not remove anything that is in use by a container, but it can remove things that are left behind after a container is shut down because the down command removes the container's dynamic data. (docker containers are made in layers there is the container image itself that gets downloaded, then there is the dynamic data that the container image may generate, then there is the user data, which is usually in a docker volume or a bind mount. All these layers combine to make the application)


    Here is an example of a simple multi-container stack with a defined network at the bottom. This deploys both of these sample containers onto the same network it is creating (edit the required storage paths to match your system or anything else that needs to be modified) There has been nothing done to change the subnets on this network. The network allows for 65534 ip addresses, which equates to 65534 containers. If I make a stack using a different network that network also allows for 65534 containers because the network is a different ip range.


    This is the "blueprint" for the build. If you remove a container and deploy with this blueprint, it will all get created the same. The things that will not be the same is the dynamic and user data if those are also removed since they are not part of the image declared for use in the compose file.

  • There are really only two things you have to worry about with docker networks:

    1) What is the network name and what containers do you have on it

    2) Does a container require a LAN ip instead of a docker ip (Things like a pihole container require this and as such need to be attached to a macvlan)

    Okey understand.



    Pruning will not remove anything that is in use by a container, but it can remove things that are left behind after a container is shut down because the down command removes the container's dynamic data.

    Ah, okay so the dynamic data gets removed.


    Thanks a lot of the useful information. I think this will solve a lot of network issues in the future. 😊

  • Copaxy

    Hat das Label gelöst hinzugefügt.
  • Dynamic data that is bound to a directory does not get removed. but when a container is taken down the build layers are removed. If it stores data in a docker volume instead of a bind mount, a volume prune will then remove that data because it is not in use by a container.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!