-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Description
The publish filter looks to be filtering on the wrong values (and the TestPsListContainersFilterPorts is incorrect); see #27557 (comment)
Create some containers;
docker run -d --name test_no_ports nginx:alpine
docker run -d --name test_port_1080 -p 1080:80 nginx:alpine
docker run -d --name test_port_1090 -p 1090:80 nginx:alpine
docker run -d --name test_port_80_random -p 80 nginx:alpine
docker run -d --name test_port_all_random -P nginx:alpine
docker ps --filter name=test_
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3ce8232cdd04 nginx:alpine "nginx -g 'daemon of…" 6 seconds ago Up 6 seconds 0.0.0.0:32775->80/tcp test_port_all_random
7f8fad7a0eb9 nginx:alpine "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds 0.0.0.0:32774->80/tcp test_port_80_random
3870ccc2f8f7 nginx:alpine "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds 0.0.0.0:1090->80/tcp test_port_1090
aa565211513e nginx:alpine "nginx -g 'daemon of…" 8 seconds ago Up 7 seconds 0.0.0.0:1080->80/tcp test_port_1080
c4a1c6e0e99b nginx:alpine "nginx -g 'daemon of…" 8 seconds ago Up 7 seconds 80/tcp test_no_portsFiltering on the "exposed" port works:
docker ps --filter name=test_ --filter expose=80
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3ce8232cdd04 nginx:alpine "nginx -g 'daemon of…" 20 seconds ago Up 19 seconds 0.0.0.0:32775->80/tcp test_port_all_random
7f8fad7a0eb9 nginx:alpine "nginx -g 'daemon of…" 21 seconds ago Up 20 seconds 0.0.0.0:32774->80/tcp test_port_80_random
3870ccc2f8f7 nginx:alpine "nginx -g 'daemon of…" 21 seconds ago Up 20 seconds 0.0.0.0:1090->80/tcp test_port_1090
aa565211513e nginx:alpine "nginx -g 'daemon of…" 22 seconds ago Up 20 seconds 0.0.0.0:1080->80/tcp test_port_1080
c4a1c6e0e99b nginx:alpine "nginx -g 'daemon of…" 22 seconds ago Up 21 seconds 80/tcp test_no_ports
docker ps --filter name=test_ --filter expose=90
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESFiltering on the "published" port doesn't (trying some variations below):
docker ps --filter name=test_ --filter publish=1080
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAME
docker ps --filter name=test_ --filter publish=1080/tcp
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker ps --filter name=test_ --filter publish=1080/udp
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESHowever, using the "exposed" port number instead of the "published" port shows some results:
docker ps --filter name=test_ --filter publish=80
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7f8fad7a0eb9 nginx:alpine "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:32774->80/tcp test_port_80_random
3870ccc2f8f7 nginx:alpine "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:1090->80/tcp test_port_1090
aa565211513e nginx:alpine "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:1080->80/tcp test_port_1080It appears it's filtering on the wrong value; also, the container with "random" port-mapping for all ports is missing in this case (perhaps it's filtering on ports that were explicitly configured to be published?)
Note that the TestPsListContainersFilterPorts test-case doesn't appear to catch this issue because it appears to be filtering on port 80 (which is published to a random port);
moby/integration-cli/docker_cli_ps_test.go
Lines 809 to 832 in b95fad8
| func (s *DockerSuite) TestPsListContainersFilterPorts(c *testing.T) { | |
| testRequires(c, DaemonIsLinux) | |
| existingContainers := ExistingContainerIDs(c) | |
| out, _ := dockerCmd(c, "run", "-d", "--publish=80", "busybox", "top") | |
| id1 := strings.TrimSpace(out) | |
| out, _ = dockerCmd(c, "run", "-d", "--expose=8080", "busybox", "top") | |
| id2 := strings.TrimSpace(out) | |
| out, _ = dockerCmd(c, "ps", "--no-trunc", "-q") | |
| assert.Assert(c, strings.Contains(strings.TrimSpace(out), id1)) | |
| assert.Assert(c, strings.Contains(strings.TrimSpace(out), id2)) | |
| out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "publish=80-8080/udp") | |
| assert.Assert(c, strings.TrimSpace(out) != id1) | |
| assert.Assert(c, strings.TrimSpace(out) != id2) | |
| out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=8081") | |
| assert.Assert(c, strings.TrimSpace(out) != id1) | |
| assert.Assert(c, strings.TrimSpace(out) != id2) | |
| out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "publish=80-81") | |
| assert.Equal(c, strings.TrimSpace(out), id1) | |
| assert.Assert(c, strings.TrimSpace(out) != id2) |
docker run -d --publish 80 busybox top
537c87330e660cc4d7a7426dcddd771a3b1bb3f7c21c7750a4b1a3358e976b1c
docker ps --filter publish=80
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
537c87330e66 busybox "top" 19 seconds ago Up 18 seconds 0.0.0.0:32776->80/tcp sleepy_khorana
...