Dynamic listening ports inside a Docker container

I have an application that, after creating some connections, using its default ports, starts opening (listening) new RANDOM ports to process only the existing connection, and then deletes them (video calls).

It also exchanges its IP address and ports inside the communication protocol, I was able to solve the problem with the IP address, but still could not find a way to dynamically tell the host computer's IPTABLES to open the same ports when they are open inside the container Docker, does anyone have any ideas?

+4
source share
1 answer

The option --net=hostfor the command docker runshould provide the behavior you are looking for - note that it is considered unsafe, but I really do not see any other means for this.

See the man page docker run:

   --net="bridge"
      Set the Network mode for the container
                                  'bridge': create a network stack on the default Docker bridge
                                  'none': no networking
                                  'container:<name|id>': reuse another container network stack
                                  'host': use the Docker host network stack. Note: the host mode gives the container full access to local system services  such  as  D-bus
   and is therefore considered insecure.
                                  '<network-name>|<network-id>': connect to a user-defined network
+2
source

Source: https://habr.com/ru/post/1628926/


All Articles