Proxy for container to manage and configure incoming connections

Hi,

I have a question and I hope someone can help me.

I created a simple docker service in 1 node, which contains 2 LAMP container. I can connect to both of them (checked it with tcpdump). My first http request goes to container1 and my second reqeust to container2, and my third back to container1 etc… (round robin concept).

How can I limit connections to a container, like container1 can only build up 16 simultaneous connections and container2 also and how can I reject connections when the limit is reached?

Is there any kind of software which can handle this? Is it able to configure it in Docker Swarm or Kubernetes or Nginx proxy? It would be an advantge when the loadbalancer / proxy can do this with TCP connections.