mirror of https://github.com/docker/docs.git
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:
parent
bfe72c6189
commit
000a37fe9d
|
@ -879,9 +879,17 @@ func (container *Container) initializeNetworking() error {
|
||||||
container.Config.Hostname = parts[0]
|
container.Config.Hostname = parts[0]
|
||||||
container.Config.Domainname = parts[1]
|
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() {
|
} else if container.hostConfig.NetworkMode.IsContainer() {
|
||||||
// we need to get the hosts files from the container to join
|
// we need to get the hosts files from the container to join
|
||||||
nc, err := container.getNetworkedContainer()
|
nc, err := container.getNetworkedContainer()
|
||||||
|
|
|
@ -40,8 +40,11 @@ func setupMountsForContainer(container *Container) error {
|
||||||
{container.ResolvConfPath, "/etc/resolv.conf", false, true},
|
{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})
|
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})
|
mounts = append(mounts, execdriver.Mount{container.HostsPath, "/etc/hosts", false, true})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue