diff --git a/CHANGELOG.md b/CHANGELOG.md index c62206434e6..dc94e725a3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ ## 1.1.3 (Unreleased) BUG FIXES: -csi: fixed a CLI panic when formatting `volume status` with `-verbose` flag [[GH-10818](https://github.com/hashicorp/nomad/issues/10818)] +* csi: Fixed a CLI panic when formatting `volume status` with `-verbose` flag [[GH-10818](https://github.com/hashicorp/nomad/issues/10818)] +* docker: Moved the generated `/etc/hosts` file's mount source to the allocation directory so that it can be shared between tasks of an allocation. [[GH-10823](https://github.com/hashicorp/nomad/issues/10823)] ## 1.1.2 (June 22, 2021) diff --git a/drivers/docker/driver.go b/drivers/docker/driver.go index 1f567ba5bb5..9682234607b 100644 --- a/drivers/docker/driver.go +++ b/drivers/docker/driver.go @@ -962,7 +962,7 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T // that comes from the pause container if task.NetworkIsolation != nil && driverConfig.NetworkMode == "" { etcHostMount, err := hostnames.GenerateEtcHostsMount( - task.TaskDir().Dir, task.NetworkIsolation, driverConfig.ExtraHosts) + task.AllocDir, task.NetworkIsolation, driverConfig.ExtraHosts) if err != nil { return c, fmt.Errorf("failed to build mount for /etc/hosts: %v", err) } diff --git a/drivers/shared/hostnames/mount.go b/drivers/shared/hostnames/mount.go index 32e23240c14..6a468097549 100644 --- a/drivers/shared/hostnames/mount.go +++ b/drivers/shared/hostnames/mount.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "net" + "os" "path/filepath" "strings" @@ -56,9 +57,14 @@ ff02::3 ip6-allhosts } path := filepath.Join(taskDir, "hosts") - err := ioutil.WriteFile(path, []byte(content.String()), 0644) - if err != nil { - return nil, err + + // tasks within an alloc should be able to share and modify the file, so + // only write to it if it doesn't exist + if _, err := os.Stat(path); os.IsNotExist(err) { + err := ioutil.WriteFile(path, []byte(content.String()), 0644) + if err != nil { + return nil, err + } } // Note that we're not setting readonly. The file is in the task dir