Skip to content

Commit e3a7db5

Browse files
committed
bugfix: failed to start container when /etc/mtab is symbol link
In some images, `/etc/mtab` is symbol link file, such as: `/etc/mtab -> /proc/mounts`, when use `/bin/cp -f` to overwrite `/etc/mtab`, it will cause error, because it will link to `/proc/mounts` file on the host. So we use the option of `--remove-destination` to remove the symbol file before overwrite it. Signed-off-by: Rudy Zhang <[email protected]>
1 parent a115eb8 commit e3a7db5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

daemon/mgr/spec_hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func setMountTab(ctx context.Context, c *Container, spec *SpecWrapper) error {
145145

146146
mtabPrestart := specs.Hook{
147147
Path: "/bin/cp",
148-
Args: []string{"-f", hostmtabPath, mtabPath},
148+
Args: []string{"-f", "--remove-destination", hostmtabPath, mtabPath},
149149
}
150150
spec.s.Hooks.Prestart = append(spec.s.Hooks.Prestart, mtabPrestart)
151151

test/cli_run_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,24 @@ func (suite *PouchRunSuite) TestRunSetRunningFlag(c *check.C) {
422422
}
423423
c.Assert(result[0].State.Running, check.Equals, true)
424424
}
425+
426+
func (suite *PouchRunSuite) TestRunWithMtab(c *check.C) {
427+
cname := "TestRunWithMtab"
428+
volumeName := "TestRunWithMtabVolume"
429+
dest := "/mnt/" + volumeName
430+
431+
command.PouchRun("volume", "create", "--name", volumeName).Assert(c, icmd.Success)
432+
defer command.PouchRun("volume", "rm", volumeName).Assert(c, icmd.Success)
433+
434+
ret := command.PouchRun("run", "--rm", "--name", cname, "-v", volumeName+":"+dest, busyboxImage, "cat", "/etc/mtab").Assert(c, icmd.Success)
435+
ret.Assert(c, icmd.Success)
436+
437+
found := false
438+
for _, line := range strings.Split(ret.Stdout(), "\n") {
439+
if strings.Contains(line, dest) {
440+
found = true
441+
break
442+
}
443+
}
444+
c.Assert(found, check.Equals, true)
445+
}

0 commit comments

Comments
 (0)