There are numerous open issues in regards to docker and DNS handling within containers: (#17190 #16619 #15978 #14627 #15819 and likely many others which I was fuzzy on)
One solution I think which would solve all these issues would be if docker acted as a DNS server. It would answer lookup requests for linked containers, and when the request isn't for a linked container, it would forward it upstream (to the host's name servers).
The /etc/hosts file inside the container would then be static, containing only the container itself.
We could also not touch /etc/hosts at all, and leave the container's entry to DNS. This would allow image builds to manipulate the file and persist the changes.
For performance, it would probably be good if docker cached the upstream DNS records. Records come back with a TTL, so docker should cache the record until this TTL expires.
There are numerous open issues in regards to docker and DNS handling within containers: (#17190 #16619 #15978 #14627 #15819 and likely many others which I was fuzzy on)
One solution I think which would solve all these issues would be if docker acted as a DNS server. It would answer lookup requests for linked containers, and when the request isn't for a linked container, it would forward it upstream (to the host's name servers).
The
/etc/hostsfile inside the container would then be static, containing only the container itself.We could also not touch
/etc/hostsat all, and leave the container's entry to DNS. This would allow image builds to manipulate the file and persist the changes.For performance, it would probably be good if docker cached the upstream DNS records. Records come back with a TTL, so docker should cache the record until this TTL expires.