Docker Community Forums

Share and learn in the Docker community.

Multi host single container connectivity?

Hello. I would like to run a python socket server on a predefined port, say 4868.
I would like multiple hosts (linux/windows/mac as well as other containers) to connect to the container on this particular port. If I try

serversocket.bind((‘0.0.0.0’, 4868))

the container will listen for incoming connections but will always accept only the first one, because it cannot bind the same (address, port) pair twice.

I would like that every connection incoming could spawn a separate thread on the container that manages the socket connection independently.
I tried running it with the command docker run -p 4868:4868 --net my-net (my-net being my custom docker network).

The very same script if ran with a simple python compiler (instead of docker container) works as expected and can accept multiple connections on the same port.

Maybe i’m missing something about docker networking. Any hint?

Any hint on this?
Bump