2

I have two docker containers in the following setup on a host machine:

  • Container 1 - UDP Port 5043 is mapped to host port 5043 (0.0.0.0:5043:5043)
  • Container 2 - Needs to send data to Container 1 on port 5043 as UDP.

Scenario 1

  1. I start Container 1 and obtain it's IP address.
  2. I use this IP address and configure Container 2 with it and start it.
  3. Container 2 is able to send UDP data to Container 1 by calling udp://Container_1_IP:5043

EVERYTHING WORKS!!

Scenario 2

  1. I start Container 1 by mapping 5043 UDP port to host's 5043 port (0.0.0.0:5043:5043)
  2. I link Container 2 and Container 1 using '--links'.
  3. Now, when Container 2 invokes the URL udp://Container_1_IP:5043, an error is thrown "Connection refused".
  4. I did verify that I am able to ping the Container 1 from inside the Container 2 using the IP.

Any help to get the Scenario 2 working for me would be really appreciated!!

4

1 回答 1

1

Docker 链接中所述:

Docker 还为源容器公开的每个端口定义了一组环境变量。
每个变量都有一个唯一的前缀,格式如下:

<name>_PORT_<port>_<protocol>

此前缀中的组件是:

  • --link 参数中指定的别名(例如,webdb)
  • <port>暴露的数量
  • a<protocol>是 TCP 或 UDP

这意味着您需要确保 Container1 使用正确的协议(在您的情况下为 UDP)公开正确的端口:请参阅“如何在 Docker 上公开 UDP 端口?

于 2015-04-10T07:13:17.213 回答