Docker容器内的动态监听端口

7

我有一个应用程序,它在使用默认端口建立一些连接后,会开始打开(监听)新的随机端口来处理现有的连接,然后关闭它们(视频通话)。

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


你执行什么命令来启动容器? - Auzias
1个回答

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

谢谢,通过使托管机器的网络在容器内可用,解决了这个问题。 - Victor H.
这听起来像是一个解决方案,但是考虑到可扩展性,运行多个相同容器实例将无法工作,因为端口被使用,除非容器在不同的IP上运行。 - Griffin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接