mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #10615 from coolljt0725/fix_mount
Fix create volume /etc cover /etc/{hosts,resolv.conf,hostname} Fixes # 10604
This commit is contained in:
commit
c2effb259d
2 changed files with 52 additions and 15 deletions
|
@ -316,8 +316,23 @@ func validMountMode(mode string) bool {
|
|||
}
|
||||
|
||||
func (container *Container) setupMounts() error {
|
||||
mounts := []execdriver.Mount{
|
||||
{Source: container.ResolvConfPath, Destination: "/etc/resolv.conf", Writable: true, Private: true},
|
||||
mounts := []execdriver.Mount{}
|
||||
|
||||
// Mount user specified volumes
|
||||
// Note, these are not private because you may want propagation of (un)mounts from host
|
||||
// volumes. For instance if you use -v /usr:/usr and the host later mounts /usr/share you
|
||||
// want this new mount in the container
|
||||
// These mounts must be ordered based on the length of the path that it is being mounted to (lexicographic)
|
||||
for _, path := range container.sortedVolumeMounts() {
|
||||
mounts = append(mounts, execdriver.Mount{
|
||||
Source: container.Volumes[path],
|
||||
Destination: path,
|
||||
Writable: container.VolumesRW[path],
|
||||
})
|
||||
}
|
||||
|
||||
if container.ResolvConfPath != "" {
|
||||
mounts = append(mounts, execdriver.Mount{Source: container.ResolvConfPath, Destination: "/etc/resolv.conf", Writable: true, Private: true})
|
||||
}
|
||||
|
||||
if container.HostnamePath != "" {
|
||||
|
@ -334,19 +349,6 @@ func (container *Container) setupMounts() error {
|
|||
}
|
||||
}
|
||||
|
||||
// Mount user specified volumes
|
||||
// Note, these are not private because you may want propagation of (un)mounts from host
|
||||
// volumes. For instance if you use -v /usr:/usr and the host later mounts /usr/share you
|
||||
// want this new mount in the container
|
||||
// These mounts must be ordered based on the length of the path that it is being mounted to (lexicographic)
|
||||
for _, path := range container.sortedVolumeMounts() {
|
||||
mounts = append(mounts, execdriver.Mount{
|
||||
Source: container.Volumes[path],
|
||||
Destination: path,
|
||||
Writable: container.VolumesRW[path],
|
||||
})
|
||||
}
|
||||
|
||||
container.command.Mounts = mounts
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2491,6 +2491,41 @@ func TestRunReuseBindVolumeThatIsSymlink(t *testing.T) {
|
|||
logDone("run - can remount old bindmount volume")
|
||||
}
|
||||
|
||||
//test create /etc volume
|
||||
func TestRunCreateVolumeEtc(t *testing.T) {
|
||||
cmd := exec.Command(dockerBinary, "run", "--dns=127.0.0.1", "-v", "/etc", "busybox", "cat", "/etc/resolv.conf")
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal("failed to run container: %v, output: %q", err, out)
|
||||
}
|
||||
if !strings.Contains(out, "nameserver 127.0.0.1") {
|
||||
t.Fatal("failed: create /etc volume cover /etc/resolv.conf")
|
||||
}
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", "-h=test123", "-v", "/etc", "busybox", "cat", "/etc/hostname")
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal("failed to run container: %v, output: %q", err, out)
|
||||
}
|
||||
if !strings.Contains(out, "test123") {
|
||||
t.Fatal("failed: create /etc volume cover /etc/hostname")
|
||||
}
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", "--add-host=test:192.168.0.1", "-v", "/etc", "busybox", "cat", "/etc/hosts")
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal("failed to run container: %v, output: %q", err, out)
|
||||
}
|
||||
out = strings.Replace(out, "\n", " ", -1)
|
||||
if !strings.Contains(out, "192.168.0.1"+"\t"+"test") || !strings.Contains(out, "127.0.0.1"+"\t"+"localhost") {
|
||||
t.Fatal("failed: create /etc volume cover /etc/hosts", out)
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("run - create /etc volume success")
|
||||
}
|
||||
|
||||
func TestVolumesNoCopyData(t *testing.T) {
|
||||
defer deleteImages("dataimage")
|
||||
defer deleteAllContainers()
|
||||
|
|
Loading…
Add table
Reference in a new issue