1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #21269 from mlaventure/inspect-bind-mounts

Update inspect/ps to properly handle bind mounts
This commit is contained in:
Vincent Demeester 2016-03-18 20:52:02 +01:00
commit 6c6363c726
3 changed files with 53 additions and 4 deletions

View file

@ -146,9 +146,14 @@ func (c *containerContext) Label(name string) string {
func (c *containerContext) Mounts() string {
c.addHeader(mountsHeader)
var name string
var mounts []string
for _, m := range c.c.Mounts {
name := m.Name
if m.Name == "" {
name = m.Source
} else {
name = m.Name
}
if c.trunc {
name = stringutils.Truncate(name, 15)
}

View file

@ -328,7 +328,11 @@ func includeContainerInList(container *container.Container, ctx *listContext) it
if ctx.filters.Include("volume") {
volumesByName := make(map[string]*volume.MountPoint)
for _, m := range container.MountPoints {
volumesByName[m.Name] = m
if m.Name != "" {
volumesByName[m.Name] = m
} else {
volumesByName[m.Source] = m
}
}
volumeExist := fmt.Errorf("volume mounted in container")

View file

@ -764,22 +764,40 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
mp := prefix + slash + "test"
dockerCmd(c, "volume", "create", "--name", "ps-volume-test")
// volume mount containers
runSleepingContainer(c, "--name=volume-test-1", "--volume", "ps-volume-test:"+mp)
c.Assert(waitRun("volume-test-1"), checker.IsNil)
runSleepingContainer(c, "--name=volume-test-2", "--volume", mp)
c.Assert(waitRun("volume-test-2"), checker.IsNil)
// bind mount container
var bindMountSource string
var bindMountDestination string
if DaemonIsWindows.Condition() {
bindMountSource = "c:\\"
bindMountDestination = "c:\\t"
} else {
bindMountSource = "/tmp"
bindMountDestination = "/t"
}
runSleepingContainer(c, "--name=bind-mount-test", "-v", bindMountSource+":"+bindMountDestination)
c.Assert(waitRun("bind-mount-test"), checker.IsNil)
out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}")
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
c.Assert(lines, checker.HasLen, 2)
c.Assert(lines, checker.HasLen, 3)
fields := strings.Fields(lines[0])
c.Assert(fields, checker.HasLen, 2)
c.Assert(fields[0], checker.Equals, "bind-mount-test")
c.Assert(fields[1], checker.Equals, bindMountSource)
fields = strings.Fields(lines[1])
c.Assert(fields, checker.HasLen, 2)
annonymounsVolumeID := fields[1]
fields = strings.Fields(lines[1])
fields = strings.Fields(lines[2])
c.Assert(fields[1], checker.Equals, "ps-volume-test")
// filter by volume name
@ -806,6 +824,28 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
fields = strings.Fields(lines[1])
c.Assert(fields[1], checker.Equals, "ps-volume-test")
// filter by bind mount source
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountSource)
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
c.Assert(lines, checker.HasLen, 1)
fields = strings.Fields(lines[0])
c.Assert(fields, checker.HasLen, 2)
c.Assert(fields[0], checker.Equals, "bind-mount-test")
c.Assert(fields[1], checker.Equals, bindMountSource)
// filter by bind mount destination
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountDestination)
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
c.Assert(lines, checker.HasLen, 1)
fields = strings.Fields(lines[0])
c.Assert(fields, checker.HasLen, 2)
c.Assert(fields[0], checker.Equals, "bind-mount-test")
c.Assert(fields[1], checker.Equals, bindMountSource)
// empty results filtering by unknown mount point
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+prefix+slash+"this-path-was-never-mounted")
c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0)