Communication between linked docker containers

会有一股神秘感。 提交于 2019-12-22 18:34:48

问题


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!!


回答1:


As mentioned in Docker links:

Docker also defines a set of environment variables for each port exposed by the source container.
Each variable has a unique prefix in the form:

<name>_PORT_<port>_<protocol>

The components in this prefix are:

  • the alias specified in the --link parameter (for example, webdb)
  • the <port> number exposed
  • a <protocol> which is either TCP or UDP

That means you need to make sure that Container1 exposes the right port with the right protocol (in your case, UDP): see "How do I expose a UDP Port on Docker?"



来源:https://stackoverflow.com/questions/29551065/communication-between-linked-docker-containers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!