From c2a25058e8c85b4d6295c6a1375c0b70b0959260 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Wed, 21 Jan 2015 14:32:36 -0800 Subject: [PATCH] Update links aliases, not name on restart Fixes #8721 Signed-off-by: Alexander Morozov --- daemon/container.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index b0eaea03b3..167e2b872f 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -1108,19 +1108,16 @@ func (container *Container) updateResolvConf(updatedResolvConf []byte, newResolv } func (container *Container) updateParentsHosts() error { - parents, err := container.daemon.Parents(container.Name) - if err != nil { - return err - } - for _, cid := range parents { - if cid == "0" { + refs := container.daemon.ContainerGraph().RefPaths(container.ID) + for _, ref := range refs { + if ref.ParentID == "0" { continue } - - c := container.daemon.Get(cid) + c := container.daemon.Get(ref.ParentID) if c != nil && !container.daemon.config.DisableNetwork && container.hostConfig.NetworkMode.IsPrivate() { - if err := etchosts.Update(c.HostsPath, container.NetworkSettings.IPAddress, container.Name[1:]); err != nil { - log.Errorf("Failed to update /etc/hosts in parent container: %v", err) + log.Debugf("Update /etc/hosts of %s for alias %s with ip %s", c.ID, ref.Name, container.NetworkSettings.IPAddress) + if err := etchosts.Update(c.HostsPath, container.NetworkSettings.IPAddress, ref.Name); err != nil { + log.Errorf("Failed to update /etc/hosts in parent container %s for alias %s: %v", c.ID, ref.Name, err) } } }