Docker在v2中构建注入链接的容器 [英] Docker Compose injecting linked containers in v2
问题描述
在Docker Compose v1中,使用链接的容器更新 / etc / hosts
文件。例如
In v1 of Docker Compose, the /etc/hosts
file is updated with linked containers. E.g.
$ cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 redis redis_1 c381c79fb9c2 romantic_yonath
172.17.0.3 48d2ed7033a1
然而,在v2中,这是通过DNS完成的,所以没有条目了。我可以使用hosts表来引导负载平衡器;非常有用,当与 scale
命令结合使用时。
However, in v2, this is done via DNS, so there are no entries anymore. I could use the hosts table to bootstrap a load balancer; very useful when used in conjunction with the scale
command.
在容器创建过程中是否有任何注入方法?
Are there any methods to inject these during container creation?
推荐答案
Nginx博客在使用DNS进行NGINX和NGINX Plus的服务发现。
NGINX缓存DNS记录,直到下一次重新启动或配置重新加载,忽略记录的TTL值。
NGINX caches the DNS records until the next restart or configuration reload, ignoring the records’ TTL values.
说明您所看到的内容在重新启动容器之后,您可以路由到新节点。
Explains what you were seeing, that after restarting the container, you are able to route to new nodes.
在启动时进行缓存的解决方法。
The section Setting the Domain Name in a Variable has an example of a workaround for caching on startup.
resolver 10.0.0.2 valid=10s;
server {
location / {
set $backend_servers backends.example.com;
proxy_pass http://$backend_servers:8080;
}
}
当您使用变量指定proxy_pass指令中的域名,NGINX在其TTL到期时重新解析域名。
When you use a variable to specify the domain name in the proxy_pass directive, NGINX re‑resolves the domain name when its TTL expires.
这个讨论建议 127.0.0.11
将是IP解压缩器在容器内部。
This discussion suggests 127.0.0.11
will be the IP of the resolver inside the container.
我在本地使用此配置确认扩展后反映的DNS更改,工作
I used this configuration locally to confirm DNS changes are reflected after scaling, and it seems to work
resolver 127.0.0.11 valid=5s;
server {
listen 80;
location / {
set $application_servers application;
proxy_pass http://$application_servers:8080;
}
}
这篇关于Docker在v2中构建注入链接的容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!