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
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 blog has this post on Using DNS for Service Discovery with NGINX and NGINX Plus.
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.
This discussion suggests
127.0.0.11
will be the IP of the resolver inside the container.I used this configuration locally to confirm DNS changes are reflected after scaling, and it seems to work