diff --git a/daemon/list.go b/daemon/list.go index 30b0a278c5..4d831460f2 100644 --- a/daemon/list.go +++ b/daemon/list.go @@ -504,7 +504,7 @@ func includeContainerInList(container *container.Container, ctx *listContext) it if nw.EndpointSettings == nil { continue } - if nw.NetworkID == value { + if strings.HasPrefix(nw.NetworkID, value) { return networkExist } } diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index 0934c2daa9..510fce78bd 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -877,6 +877,23 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) { containerOut = strings.TrimSpace(string(out)) c.Assert(containerOut, checker.Contains, "onbridgenetwork") + + // Filter by partial network ID + partialnwID := string(nwID[0:4]) + + out, _ = dockerCmd(c, "ps", "--filter", "network="+partialnwID) + containerOut = strings.TrimSpace(string(out)) + + lines = strings.Split(containerOut, "\n") + // skip header + lines = lines[1:] + + // ps output should have only one container + c.Assert(lines, checker.HasLen, 1) + + // Making sure onbridgenetwork is on the output + c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n")) + } func (s *DockerSuite) TestPsByOrder(c *check.C) {