Docker容器内的动态侦听端口

Vic*_* H. 6 linux iptables docker

我有一个应用程序,在使用其默认端口建立连接后,开始打开(侦听)新的RANDOM端口以处理现有连接,然后丢弃它们(视频呼叫).

它还在通信协议内交换其IP地址和端口,我能够解决IP地址问题,但仍然无法找到一种方法来动态告诉主机的IPTABLES在Docker中打开它们时打开相同的端口容器,任何人有什么想法?

Auz*_*ias 4

该命令--net=host的选项docker run应该启用您正在寻求的行为 - 请注意,它被认为是不安全的,但我确实没有看到任何其他方法可以做到这一点。

请参阅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's 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
Run Code Online (Sandbox Code Playgroud)