fix(daemon): prepend host /etc/hosts instead of bind mounting

systemd systems do not require a /etc/hosts file exists since an nss
module is shipped that creates localhost implicitly. So, mounting
/etc/hosts can fail on these sorts of systems, as was reported on CoreOS
in issue #5812.

Instead of trying to bind mount just copy the hosts entries onto the
containers private /etc/hosts.

Docker-DCO-1.1-Signed-off-by: Brandon Philips <brandon.philips@coreos.com> (github: philips)
This commit is contained in:
Brandon Philips 2014-05-16 15:01:25 -07:00
parent bfe72c6189
commit 000a37fe9d
2 changed files with 14 additions and 3 deletions

View file

@ -879,9 +879,17 @@ func (container *Container) initializeNetworking() error {
container.Config.Hostname = parts[0]
container.Config.Domainname = parts[1]
}
container.HostsPath = "/etc/hosts"
return container.buildHostnameFile()
content, err := ioutil.ReadFile("/etc/hosts")
if os.IsNotExist(err) {
return container.buildHostnameAndHostsFiles("")
}
if err != nil {
return err
}
container.HostsPath = container.getRootResourcePath("hosts")
return ioutil.WriteFile(container.HostsPath, content, 0644)
} else if container.hostConfig.NetworkMode.IsContainer() {
// we need to get the hosts files from the container to join
nc, err := container.getNetworkedContainer()

View file

@ -40,8 +40,11 @@ func setupMountsForContainer(container *Container) error {
{container.ResolvConfPath, "/etc/resolv.conf", false, true},
}
if container.HostnamePath != "" && container.HostsPath != "" {
if container.HostnamePath != "" {
mounts = append(mounts, execdriver.Mount{container.HostnamePath, "/etc/hostname", false, true})
}
if container.HostsPath != "" {
mounts = append(mounts, execdriver.Mount{container.HostsPath, "/etc/hosts", false, true})
}