链接码头箱容器之间的通信
问题描述:
在主机上的以下设置中,我有两个docker容器:
I have two docker containers in the following setup on a host machine:
- 容器1 - UDP端口5043映射到主机端口5043(0.0.0.0:5043:5043)
- 容器2 - 需要将数据发送到端口5043上的容器1作为UDP 。
- 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.
- 我开始容器1并获取其IP地址。
- 我使用此IP地址并配置容器2并启动它。
- 容器2能够通过调用
发送UDP数据到容器1 udp:// Container_1_IP:5043
- I start Container 1 and obtain it's IP address.
- I use this IP address and configure Container 2 with it and start it.
- Container 2 is able to send UDP data to Container 1 by calling
udp://Container_1_IP:5043
一切工作!!
- 我通过映射启动Container 1 5043 UDP端口到主机的5043端口(
0.0.0.0:5043:5043
) - 我链接容器2和容器1使用' code> - 链接'。
- 现在,当Container 2调用URL
udp:// Container_1_IP:5043
,将抛出错误连接拒绝
。 - 我确认我能够从容器内部ping容器1 2使用IP。
- I start Container 1 by mapping 5043 UDP port to host's 5043 port (
0.0.0.0:5043:5043
) - I link Container 2 and Container 1 using '
--links
'. - Now, when Container 2 invokes the URL
udp://Container_1_IP:5043
, an error is thrown "Connection refused
". - I did verify that I am able to ping the Container 1 from inside the Container 2 using the IP.
任何有助于让场景2为我工作的帮助将非常感激!
Any help to get the Scenario 2 working for me would be really appreciated!!
答
如 Docker链接:
Docker还为源容器暴露的每个端口定义了一组环境变量。 br>
每个变量都有一个唯一的前缀,格式如下:
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:
- --link参数中指定的别名(例如,webdb)
-
端口>
数字曝光 - a
< protocol>
/ strong>
- the alias specified in the --link parameter (for example, webdb)
- the
<port>
number exposed - a
<protocol>
which is either TCP or UDP
这意味着您需要确保Container1向右显示正确的端口协议(在您的情况下为UDP):请参见如何在Docker上公开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?"