From fa5e032e495bd8749fe252a6ec7f0739aba70dd8 Mon Sep 17 00:00:00 2001 From: Konstantin Suvorov Date: Tue, 15 Aug 2017 20:25:48 +0300 Subject: [PATCH] Register container name and its network aliases with weaveDNS --- plugin/net/watcher.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin/net/watcher.go b/plugin/net/watcher.go index b763d1a6..f0c91fdb 100644 --- a/plugin/net/watcher.go +++ b/plugin/net/watcher.go @@ -39,8 +39,16 @@ func (w *watcher) ContainerStarted(id string) { if network.isOurs { if w.driver.dns { fqdn := fmt.Sprintf("%s.%s", info.Config.Hostname, info.Config.Domainname) - if err := w.weave.RegisterWithDNS(id, fqdn, net.IPAddress); err != nil { - w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err) + weaveDomain, _ := w.weave.DNSDomain() + // Container name is prefixed with '/' so we cut first character + name := fmt.Sprintf("%s.%s", info.Name[1:], weaveDomain) + aliases := append([]string(nil), fqdn, name) + aliases = append(aliases, net.Aliases...) + for _, alias := range aliases { + w.driver.debug("ContainerStarted", "going to register %s with weaveDNS", alias) + if err := w.weave.RegisterWithDNS(id, alias, net.IPAddress); err != nil { + w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err) + } } } netNSPath := weavenet.NSPathByPidWithProc(w.driver.procPath, info.State.Pid)