Skip to content

Add publish and expose filter for docker ps --filter#27557

Merged
vdemeester merged 1 commit intomoby:masterfrom
yongtang:27178-ps-filter-publish-expose
Feb 1, 2017
Merged

Add publish and expose filter for docker ps --filter#27557
vdemeester merged 1 commit intomoby:masterfrom
yongtang:27178-ps-filter-publish-expose

Conversation

@yongtang
Copy link
Member

- What I did

This fix tries to address the enhancement proposal raised in #27178 for filtering based on published or exposed ports of docker ps --filter.

Note: this PR didn't implement the wildcard match initially, as protocol (tcp/udp) has to be taken into consideration. But is open to suggestions.

- How I did it

In this fix, two filter options, publish and expose have been added to take either <port>[/<protocol>] or <from>-<to>[/<protocol>] and filtering on containers.

- How to verify it

An integration test has been added to cover the changes.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

This fix fixes #27178.

Signed-off-by: Yong Tang [email protected]

@vdemeester
Copy link
Member

Design SGTM 👼

daemon/list.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why it's never returning error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @LK4D4. I wasn't sure initially as some of the other filters didn't return the error. The PR has been updated and now expose and publish will return error.

@LK4D4
Copy link
Contributor

LK4D4 commented Nov 3, 2016

@yongtang would you mind to rebase? Thanks!

@yongtang yongtang force-pushed the 27178-ps-filter-publish-expose branch 2 times, most recently from 143e04b to 07ccfde Compare November 4, 2016 00:19
@yongtang
Copy link
Member Author

yongtang commented Nov 4, 2016

Thanks @LK4D4 for the review. The PR has been updated and rebased. Please take a look and let me know if there are any issues.

@yongtang yongtang force-pushed the 27178-ps-filter-publish-expose branch from 07ccfde to 902335e Compare November 8, 2016 03:42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could add -q and use checker.Equals instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mlaventure. Done.

Copy link
Contributor

@mlaventure mlaventure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with inconsequential nit

@mlaventure
Copy link
Contributor

ping @LK4D4

@yongtang yongtang force-pushed the 27178-ps-filter-publish-expose branch from 902335e to 91e1432 Compare December 1, 2016 19:04
@yongtang
Copy link
Member Author

yongtang commented Dec 1, 2016

Thanks all for the review. The PR has been updated. Please take a look and let me know if there are any other issues.

@vdemeester vdemeester added this to the 1.14.0 milestone Dec 2, 2016
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM but I feel the logrus.Errorf shouldn't be there 👼

daemon/list.go Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yongtang debug message 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. How could I have missed this one? 😳

@yongtang yongtang force-pushed the 27178-ps-filter-publish-expose branch from 91e1432 to a548a44 Compare January 13, 2017 01:56
@yongtang
Copy link
Member Author

Thanks @vdemeester. The PR has been updated.

@yongtang yongtang force-pushed the 27178-ps-filter-publish-expose branch from a548a44 to 3257ff7 Compare January 13, 2017 04:14
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐸
/cc @thaJeztah for docs review 👼

@mlaventure
Copy link
Contributor

ping @thaJeztah

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

port is 80, protocol is tcp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda The PR has been updated. Thanks.

@yongtang yongtang force-pushed the 27178-ps-filter-publish-expose branch from 3257ff7 to 4ba69bd Compare January 19, 2017 11:08
@LK4D4
Copy link
Contributor

LK4D4 commented Jan 27, 2017

@yongtang needs rebase
@thaJeztah for docs-review

This fix tries to address the enhancement proposal raised in
27178 for filtering based on published or exposed ports of
`docker ps --filter`.

In this fix, two filter options, `publish` and `expose` have
been added to take either `<port>[/<protocol>]` or `<from>-<to>[/<protocol>]`
and filtering on containers.

An integration test has been added to cover the changes.

This fix fixes 27178.

Signed-off-by: Yong Tang <[email protected]>
@yongtang yongtang force-pushed the 27178-ps-filter-publish-expose branch from 4ba69bd to 743943f Compare January 27, 2017 21:26
@yongtang
Copy link
Member Author

@LK4D4 @thaJeztah The PR has been rebased. Thanks.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs LGTM
/cc @thaJeztah for revisit 👼

@thaJeztah
Copy link
Member

@yongtang can you;

@yongtang
Copy link
Member Author

yongtang commented Feb 2, 2017

Thanks @thaJeztah. A PR #30661 has been created for the API history and man page. Please take a look.

yongtang added a commit to yongtang/docker that referenced this pull request Feb 7, 2017
This fix updates API history and man page for
`docker ps --filter expose/publish`, from the feedback:
moby#27557 (comment)

Signed-off-by: Yong Tang <[email protected]>
tiborvass pushed a commit to tiborvass/cli that referenced this pull request May 11, 2017
This fix updates API history and man page for
`docker ps --filter expose/publish`, from the feedback:
moby/moby#27557 (comment)

Signed-off-by: Yong Tang <[email protected]>
andrewhsu pushed a commit to docker-archive/docker-ce that referenced this pull request Jun 5, 2017
This fix updates API history and man page for
`docker ps --filter expose/publish`, from the feedback:
moby/moby#27557 (comment)

Signed-off-by: Yong Tang <[email protected]>
Upstream-commit: d77db0bd9ac80a3a2e7ad4d90b6aa33fe4fc0462
Component: cli
dnephin pushed a commit to dnephin/cli that referenced this pull request Jun 14, 2017
This fix updates API history and man page for
`docker ps --filter expose/publish`, from the feedback:
moby/moby#27557 (comment)

Signed-off-by: Yong Tang <[email protected]>
@Tusenka
Copy link

Tusenka commented Jan 24, 2020

It doesn't work for me( I can filter only port to, not from

@thaJeztah
Copy link
Member

Yes, something looks to be off.

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_ports

Filtering 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               NAMES

Filtering 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                 NAMES

However, 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_1080

It 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);

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
...

@thaJeztah
Copy link
Member

opened #40405

kolyshkin pushed a commit to kolyshkin/moby that referenced this pull request May 4, 2020
Reuse existing structures and rely on json serialization to deep copy
Container objects.

Also consolidate all "save" operations on container.CheckpointTo, which
now both saves a serialized json to disk, and replicates state to the
ACID in-memory store.

Signed-off-by: Fabio Kung <[email protected]>
(cherry picked from commit edad527)
Signed-off-by: Kir Kolyshkin <[email protected]>

Conflicts:
 - daemon/container_operations.go: missing
   moby#30117
 - daemon/daemon.go: missing moby#32821
 - daemon/list.go: missing moby#27557,
   moby#33241 etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request for docker --filter : ability to search by PORT number, exposed or published and all published

8 participants