How to configure docker to limit the range of ports for spinning up containers

We are using Jenkins and docker for doing CI/CD. Our Jenkins is setup as master/slave style, where slaves are distributed across different data centers. when a new build needs to happen Jenkins master identifies a slave in one of the DC and spin up a ephemeral container and tear it down once done.

Due to firewall limitations, we only have about 10 ports open for the slaves in some of the DCs. for example Port Range: 8000 - 8010. In general docker uses the linux port ranges 32768 to 61000. The problem is Jenkins master can not talk to the containers if the host port is bound out of 8000 - 8010. Jenkins docker plugin has limitation where you can not bind multiple ports (may be I am wrong here). I would like to know if any way we can configure this at docker end or in Jenkins docker plugin.

Hi harikrish00, I have the same issue. I am using Docker Swarm to allow containers on different hosts to communicate. Have you found a solution to limiting the range of ephemeral ports in the Docker Container? Unfortunately, changing the local port range on the host does not change the container ephemeral port range…

Did anyone figure this out? It would help me a lot.

In docker template container settings in jenkins. Add port bindings: