From 0477d61856d01c7164a2fb692afa2a18e27244e0 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Wed, 16 Mar 2016 13:26:15 -0700 Subject: [PATCH 1/3] Fix inspect to print bind mounts source path instead of an empty string Signed-off-by: Kenfe-Mickael Laventure Upstream-commit: cb8cc56c225cfc74b81f22a0f2ca8ce7bdccfe04 Component: engine --- components/engine/api/client/formatter/custom.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/engine/api/client/formatter/custom.go b/components/engine/api/client/formatter/custom.go index 9ac457a414..2bb26a3dbe 100644 --- a/components/engine/api/client/formatter/custom.go +++ b/components/engine/api/client/formatter/custom.go @@ -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) } From 9fd3d4a31efcd688c4f18e725132d8e6852919e2 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Wed, 16 Mar 2016 14:10:16 -0700 Subject: [PATCH 2/3] Update filter volume to allow filtering by bind mount source Signed-off-by: Kenfe-Mickael Laventure Upstream-commit: 8451a08ed52b976fffb0cf34be0a48dcc36bdcbe Component: engine --- components/engine/daemon/list.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/engine/daemon/list.go b/components/engine/daemon/list.go index 3bc819a79f..8f0a50de66 100644 --- a/components/engine/daemon/list.go +++ b/components/engine/daemon/list.go @@ -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") From 98172de036c3d5ff56b30bce3c250a56fb656b81 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Wed, 16 Mar 2016 16:15:04 -0700 Subject: [PATCH 3/3] Update TestPsShowMounts to also test bind mounts Signed-off-by: Kenfe-Mickael Laventure Upstream-commit: cdd7fddfec70cca2cc228519794281988ef2a15a Component: engine --- .../integration-cli/docker_cli_ps_test.go | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/components/engine/integration-cli/docker_cli_ps_test.go b/components/engine/integration-cli/docker_cli_ps_test.go index cc32194d5a..72650ff21c 100644 --- a/components/engine/integration-cli/docker_cli_ps_test.go +++ b/components/engine/integration-cli/docker_cli_ps_test.go @@ -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)