Skip to content

Commit 59b70cd

Browse files
author
dattatrayakumbhar04
committed
28722: List of containers with networkID filter is not working
Signed-off-by: dattatrayakumbhar04 <dattatraya.kumbhar@gslab.com>
1 parent 05cd8be commit 59b70cd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

daemon/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ func includeContainerInList(container *container.Container, ctx *listContext) it
504504
if nw.EndpointSettings == nil {
505505
continue
506506
}
507-
if nw.NetworkID == value {
507+
if strings.HasPrefix(nw.NetworkID, value) {
508508
return networkExist
509509
}
510510
}

integration-cli/docker_cli_ps_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,23 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
877877
containerOut = strings.TrimSpace(string(out))
878878

879879
c.Assert(containerOut, checker.Contains, "onbridgenetwork")
880+
881+
// Filter by partial network ID
882+
partialnwID := string(nwID[0:4])
883+
884+
out, _ = dockerCmd(c, "ps", "--filter", "network="+partialnwID)
885+
containerOut = strings.TrimSpace(string(out))
886+
887+
lines = strings.Split(containerOut, "\n")
888+
// skip header
889+
lines = lines[1:]
890+
891+
// ps output should have only one container
892+
c.Assert(lines, checker.HasLen, 1)
893+
894+
// Making sure onbridgenetwork is on the output
895+
c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
896+
880897
}
881898

882899
func (s *DockerSuite) TestPsByOrder(c *check.C) {

0 commit comments

Comments
 (0)