Docker链接的容器,Docker网络,组合网络-我们现在应该如何``链接''容器 [英] Docker linked containers, Docker Networks, Compose Networks - how should we now 'link' containers

查看:89
本文介绍了Docker链接的容器,Docker网络,组合网络-我们现在应该如何``链接''容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的应用程序,其中包含在同一主机上运行的4个Docker容器。它们已经使用 link 命令链接在一起。

I have an existing app that comprises of 4 docker containers running on the same host. They have been linked together using the link command.

但是,在对docker进行一些升级之后, link 行为已被弃用,并且似乎已更改。我们遇到了容器之间现在失去彼此链接的问题。

However, after some upgrades of docker, the link behaviour has been deprecated, and changed it seems. We are having issues where containers are loosing the link to each other now.

因此,码头工人说要使用新的 Network 具有链接容器的功能。但是我看不到它是如何工作的。

So, docker says to use the new Network feature over linked containers. But I can't see how this works.

如果两个容器在同一个网络中,则相同的 ENV vars是否像链接在一起一样自动暴露在容器上?

If 2 containers are in the same network, are the same ENV vars automatically exposed on the containers as if they were linked?

还是用正确的容器名称/ ip地址更新了主机文件?即使在 docker重新启动之后?

Or is the hosts file updated with the correct container name / ip addresses ? Even after a docker restart ?

我在文档中看不到容器如何在其网络中找到另一个容器的位置?

I can't see in the docs how a container can find the location of another in its network?

此外,撰写看起来具有链接容器的简单设置,并且可能使其中的一些操作自动化-它将成为定义多个容器应用程序的方法吗?还是在生产中运行它为时过早?

Also, compose looks to have a simple set up for linking containers, and may automate some of this - would compose be the way to go for defining multi container apps? Or is it too soon to run it in production?

组成也支持多主机配置吗?

Does compose support multiple host configuration as well?

将来,我们可能需要将其中一个容器移到其他主机上。...

at some point in the future we will probably need to move one of the containers to a different host....

推荐答案


如果两个容器位于同一网络中,相同的ENV变量是否会像链接在一起一样自动暴露在容器上?

If 2 containers are in the same network, are the same ENV vars automatically exposed on the containers as if they were linked?

否,您现在必须使用容器名称作为其主机名。新的网络功能不知道将使用哪个端口。可以将这视为两台计算机插入同一网络集线器。两者都可以通过其主机名来寻址另一个。

no, you would now have to use the container names as their hostnames. The new network feature has no idea which ports will be used. Think of this as 2 computers plugged on the same network hub. Both can address the other one by its hostname.


是否使用正确的容器名称/ ip地址更新了主机文件?即使在docker重新启动后?

is the hosts file updated with the correct container name / ip addresses ? Even after a docker restart ?

是, / etc / hosts 文件用于网络中的所有容器都将由docker引擎实时更新。

yes, /etc/hosts files for all containers which are part of a network will be updated live by the docker engine.


我在文档中看不到容器如何在其网络中找到另一个容器的位置?

I can't see in the docs how a container can find the location of another in its network?

使用容器名称。请参见<< a href = https://docs.docker.com/engine/userguide/networking/work-with-networks/#connect-containers rel = nofollow>连接容器部分em>使用网络命令 doc:
连接后,容器可以使用另一个容器的IP地址或名称进行通信。

Using the container name. See the Connect containers section of the Work with network commands doc: Once connected, the containers can communicate using another container’s IP address or name.


此外,compose看起来有一个简单的链接容器设置,并且可以使其中一些自动化-可以使用compose定义多个容器应用程序吗?还是在生产环境中运行它为时过早?

Also, compose looks to have a simple set up for linking containers, and may automate some of this - would compose be the way to go for defining multi container apps? Or is it too soon to run it in production?

Compose通过提供-x-网络选项。您不应在生产中使用(当前的Compose版本为1.5)。

Compose supports the new network feature as beta by offering the --x-networking option. You should not use it in production yet (current Compose version is 1.5).

此外,当前实现有些不便,因为我们必须使用由项目名称 + <$ c组成的完整容器名称$ c> _ + 容器名称 + _1 文档表示下一个版本(当前版本为1.5)将对此进行改进,因此我们不应必须担心项目名称来寻址容器。

Furthermore, the current implementation is a bit inconvenient as we must use the full container name which is composed of the project name + _ + container name + _1. The documentation says the next version (current one is 1.5) will improve this so that we should not have to worry about the project name to address containers.


compose是否还支持多主机配置? / p>

Does compose support multiple host configuration as well?

是的,与Swarm结合使用,如重叠网络文档

Yes, in conjonction with Swarm as detailed in the overlay network documentation

这篇关于Docker链接的容器,Docker网络,组合网络-我们现在应该如何``链接''容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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