Don't delete another container's resolv and hosts files
The logic of deleting and recreating /etc/hosts and
/etc/resolv.conf only makes sense when we're the one that creates
the files - when we don't, it just removes them, and there's
nothing left to use.
Fixes
@@ -665,7 +665,9 @@ func (c *Container) makeBindMounts() error {
if !netDisabled {
// If /etc/resolv.conf and /etc/hosts exist, delete them so we
- // will recreate
+ // will recreate. Only do this if we aren't sharing them with
+ // another container.
+ if c.config.NetNsCtr == "" {
if path, ok := c.state.BindMounts["/etc/resolv.conf"]; ok {
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
return errors.Wrapf(err, "error removing container %s resolv.conf", c.ID())
@@ -678,6 +680,7 @@ func (c *Container) makeBindMounts() error {
}
delete(c.state.BindMounts, "/etc/hosts")
}
+ }
if c.config.NetNsCtr != "" {
// We share a net namespace
