Skip to content

Commit

Permalink
bugfix: failed to start container when /etc/mtab is symbol link
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rudyfly committed Aug 2, 2018
1 parent a115eb8 commit e3a7db5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion daemon/mgr/spec_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func setMountTab(ctx context.Context, c *Container, spec *SpecWrapper) error {

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

Expand Down
21 changes: 21 additions & 0 deletions test/cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,24 @@ func (suite *PouchRunSuite) TestRunSetRunningFlag(c *check.C) {
}
c.Assert(result[0].State.Running, check.Equals, true)
}

func (suite *PouchRunSuite) TestRunWithMtab(c *check.C) {
cname := "TestRunWithMtab"
volumeName := "TestRunWithMtabVolume"
dest := "/mnt/" + volumeName

command.PouchRun("volume", "create", "--name", volumeName).Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", volumeName).Assert(c, icmd.Success)

ret := command.PouchRun("run", "--rm", "--name", cname, "-v", volumeName+":"+dest, busyboxImage, "cat", "/etc/mtab").Assert(c, icmd.Success)
ret.Assert(c, icmd.Success)

found := false
for _, line := range strings.Split(ret.Stdout(), "\n") {
if strings.Contains(line, dest) {
found = true
break
}
}
c.Assert(found, check.Equals, true)
}

0 comments on commit e3a7db5

Please sign in to comment.