链接码头箱容器之间的通信 [英] Communication between linked docker containers

查看:136
本文介绍了链接码头箱容器之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在主机上的以下设置中,我有两个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. 我开始容器1并获取其IP地址。

  2. 我使用此IP地址并配置容器2并启动它。

  3. 容器2能够通过调用发送UDP数据到容器1 udp:// Container_1_IP:5043

  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

一切工作!!


  1. 我通过映射启动Container 1 5043 UDP端口到主机的5043端口( 0.0.0.0:5043:5043

  2. 我链接容器2和容器1使用' code> - 链接'。

  3. 现在,当Container 2调用URL udp:// Container_1_IP:5043 ,将抛出错误连接拒绝

  4. 我确认我能够从容器内部ping容器1 2使用IP。

  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.

任何有助于让场景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?"

这篇关于链接码头箱容器之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆