diff --git a/daemon/container.go b/daemon/container.go index f359adfe0a..df6bd66190 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -849,18 +849,16 @@ func (container *Container) setupContainerDns() error { daemon = container.daemon ) - if config.NetworkMode == "host" { - container.ResolvConfPath = "/etc/resolv.conf" - return nil - } - resolvConf, err := resolvconf.Get() if err != nil { return err } + container.ResolvConfPath, err = container.getRootResourcePath("resolv.conf") + if err != nil { + return err + } - // If custom dns exists, then create a resolv.conf for the container - if len(config.Dns) > 0 || len(daemon.config.Dns) > 0 || len(config.DnsSearch) > 0 || len(daemon.config.DnsSearch) > 0 { + if config.NetworkMode != "host" && (len(config.Dns) > 0 || len(daemon.config.Dns) > 0 || len(config.DnsSearch) > 0 || len(daemon.config.DnsSearch) > 0) { var ( dns = resolvconf.GetNameservers(resolvConf) dnsSearch = resolvconf.GetSearchDomains(resolvConf) @@ -875,18 +873,9 @@ func (container *Container) setupContainerDns() error { } else if len(daemon.config.DnsSearch) > 0 { dnsSearch = daemon.config.DnsSearch } - - resolvConfPath, err := container.getRootResourcePath("resolv.conf") - if err != nil { - return err - } - container.ResolvConfPath = resolvConfPath - return resolvconf.Build(container.ResolvConfPath, dns, dnsSearch) - } else { - container.ResolvConfPath = "/etc/resolv.conf" } - return nil + return ioutil.WriteFile(container.ResolvConfPath, resolvConf, 0644) } func (container *Container) initializeNetworking() error { diff --git a/daemon/volumes.go b/daemon/volumes.go index ea18a62b8c..b60118c953 100644 --- a/daemon/volumes.go +++ b/daemon/volumes.go @@ -50,15 +50,15 @@ func prepareVolumesForContainer(container *Container) error { func setupMountsForContainer(container *Container) error { mounts := []execdriver.Mount{ - {container.ResolvConfPath, "/etc/resolv.conf", false, true}, + {container.ResolvConfPath, "/etc/resolv.conf", true, true}, } if container.HostnamePath != "" { - mounts = append(mounts, execdriver.Mount{container.HostnamePath, "/etc/hostname", false, true}) + mounts = append(mounts, execdriver.Mount{container.HostnamePath, "/etc/hostname", true, true}) } if container.HostsPath != "" { - mounts = append(mounts, execdriver.Mount{container.HostsPath, "/etc/hosts", false, true}) + mounts = append(mounts, execdriver.Mount{container.HostsPath, "/etc/hosts", true, true}) } // Mount user specified volumes