Is there a way to limit the number of maximum containers that can attach to a Docker Network?

Hi folks!

I am using Docker on shared super computer for users to deploy their images and run containers. The shared super computer has several GPUs, RAM and CPU cores on an Ubuntu distro.

I would like to constrain Docker container resources (CPU, RAM and GPU count), which I believe I have solution(s) to stop users hoarding resources and blocking other users from deploying and executing their containers.

One area that I am trying to figure out is how to constrain the number of IP addresses are consumed per container. I have a limited number of available IP addresses in the subnet for Docker to allocate containers (this is constrained in the Docker daemon.json). We also have a Docker manager app that is used to manage containers. For example, 2 containers may want to communicate to each other so they will share a Docker network between them to allow communication. However, in the case where there is a single isolated container, we create a Docker network to allow the each app and container to communicate. In this case, I would limit the number of the containers that can join this Docker network to just 2 containers (managing app and container). Is this possible via the Docker Engine API?

Trudging through the Docker Engine API, I think I can configure the IPAMConfig , but I’m not sure how it works as the documentation is making it immediately clear.