Docker Community Forums

Share and learn in the Docker community.

Mutliple conatiners sharing the same ports on host system


Sorry for the daft question!

I have a conatiner that mimics the embedded OS on a device - essentailly these monitor and grab the value of a sesnor that i’ve simulated and publish it as a web service. I’ve mapped the ports to the host system that are required for my software to communicate with it (I’ve still not quite got it working yet - please see my other post “Dockerising an embedded distro” if you can help!!!).

Part of the reason for dockerising is to spin up mutiple copies of the image as new containers so I can mimic having a cluster of these tiny IoT devices (not sure if this is a good idea?!).

Unfortunatly, I can’t change the ports since these are hardwired into the embedded OS and also the software we use to connect to them expects to use these ports - normally these would have their own IP address so having the same port wouldn’t matter.

How do map the same ports to different conatiners on the same system - is there a work around for this type of thing?

Many thanks!

You might want to consider to add a reverse proxy that use subdomain based proxy rules to mix. Though you will need to solve that these subomains resolv to your host (either by dns Or by manipulating /etc/hosts).

If this is not feasable, you might want to research about MACVLAN.

Thanks Metin - half the battle is finding the terminiology and knowing what to search for!

I’ve found this example for a reverse proxy within a docker environment so will give it ago!