在Docker中链接容器 [英] Linking containers in Docker

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

问题描述

Docker允许您按名称链接容器.

Docker allows you to link containers by name.

对此我有两个问题:

  • 假定的 A (客户端)链接到 B (服务),并且 B 的端口是动态暴露的(即,实际主机端口由Docker决定,而不是由用户提供).如果 B 发生故障并重新启动,会发生什么情况?
    • Docker是否在 A 上更新环境变量?
    • Docker是否再次将相同的端口分配给 B ?
    • A B 的链接是否断开?
    • …?
    • Supposed A (client) is linked to B (service), and B's port is exposed dynamically (i.e. the actual host port is determined by Docker, not given by the user). What happens if B goes down and is being restarted?
      • Does Docker update the environment variable on A?
      • Does Docker assign the very same port again to B?
      • Is A link to B broken?
      • …?

      推荐答案

      我会说:try;).

      此刻,码头工人一开始就没有任何控制权,就开始执行 execve(3)而不使用fork.无法更新环境,这就是为什么链接需要在容器运行之前完成,并且以后不能进行编辑.

      At the moment, docker as no control whatsoever on the process once started as it execve(3) without fork. It is not possible to update the env, that's why the links need to be done before the container runs and can't be edited afterward.

      Docker将尝试将相同的端口重新分配给B,但是没有保证,因为其他容器可能正在使用它.

      Docker will try to reassign the same port to B, but there is no warranty as an other container could be using it.

      破损"是什么意思?如果您禁用了未链接的容器之间的联网,则在停止/启动容器时,该网络仍将正常工作.

      What do you mean by 'broken'? If you disabled the networking between unlinked container, it should still be working if you stop/start a container.

      否,您还不能跨网络链接容器.

      No, you can't link container across network yet.

      这篇关于在Docker中链接容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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