allow /etc/hosts /etc/resolv.conf and /etc/hostname to be changed

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
Victor Vieux 2014-04-09 23:17:39 +00:00 committed by Victor Vieux
parent 366fe67946
commit f3b2c93b9f
2 changed files with 9 additions and 20 deletions

View file

@ -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 {

View file

@ -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