Q:

How to host more than 65536 services, each requiring a distinct port?

I want to host web services (say a simple nodejs api service)
There is a limitation on the number of services that I can host on a single host, since the number of ports available on a host is only 65536. 
I can think of having a virtual sub-network that is visible only within the host and then have a proxy server that sits on the host and routes the APIs to the appropriate web-service. 
Is it possible to do this with dockers - where each service is deployed in a container, a proxy server routing the APIs to the appropriate container?
Is there any off the shelf solution for this (preferably free of cost).

A:

First of all, I doubt you can run 65536 processes per host, unless it's huge. Anyway, I would not recommend that because of availability and performance. Too many processes will be competing for the same resources, leading to a lot of context switches. That said, it's doable.
If your services are HTTP you can use a reverse proxy, like nginx or traefik. If not, you can use HAProxy for TCP services. Traefik is a better option because it performs service discovery, so you won't need to configure the endpoints manually.
In this setup the networking should be bridge, which is the default in Docker. Every container will have its own IP address, so you won't have any problem regarding port exhaustion.

