且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Docker链接的容器,Docker网络,组合网络-我们现在应该如何``链接''容器

更新时间:2023-09-15 13:07:58


如果两个容器位于同一网络中,相同的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?

使用容器名称。请参见连接容器部分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).

此外,当前实现有些不便,因为我们必须使用由项目名称 + _ + 容器名称 + _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