Skip to content

Add docker ps ancestor filter for image#14570

Merged
thaJeztah merged 1 commit intomoby:masterfrom
vdemeester:13365-ps-image-filter
Aug 28, 2015
Merged

Add docker ps ancestor filter for image#14570
thaJeztah merged 1 commit intomoby:masterfrom
vdemeester:13365-ps-image-filter

Conversation

@vdemeester
Copy link
Member

Makes it possible to filter containers by image ancestor, using --filter=ancestor=busybox or --filter=ancestor=8c2e06607696. This is related to #13365, and for the image filter, it's actually ask sometimes on irc 🐸.

The ancestor filter support the following notation:

  • image
  • image:tag
  • image@digest
  • short-id
  • full-id

Still to do :

  • Support multiple --filter=ancestor
  • Complete integration tests with short-id to make sure it works
  • Add integration tests with image@digest

Signed-off-by: Vincent Demeester [email protected]

@vdemeester vdemeester changed the title Add ps filter for image Add docker ps filter for image Jul 12, 2015
@duglin
Copy link
Contributor

duglin commented Jul 12, 2015

what about containers that have that image the distant history? e.g. the image in question was used to make another image and that's 2nd image is the one used to create the container.

@vdemeester
Copy link
Member Author

Ah 😝, this would make it way more complicated to implement then 😅, and I'm not sure how you would handle from a user point of view.

Given that it was implement
And I have 3 images : base -> middle -> final
When I'm doing ``--filter=image=middle``
Then should it filter all containers based on middle and final, or just those with final ?

I think the simpler the better (just filter with the image used when starting the container). And I don't really see a use case for distant history — I might be wrong though.

@icecrime
Copy link
Contributor

I only see (potential) value is we walk the ancestry tree, the easy case I can pretty much grep :-( Not convinced.

@vdemeester
Copy link
Member Author

@icecrime On the other hand I'm not convinced on the grep part 😊 (although I like grep a lot 😺). There is a few cases where I wouldn't find grep useful:

  • Same or common part of the name shared by some images and some containers :
$ docker ps -a | grep busybox
5c33c99ac89f        busybox         […]                         toto                
5ba009755259        maven           […]                         busybox1            
2aff61195a5a        maven           […]                         busybox  
  • The ability to chain it. Let's say I want to stop all container based on the busybox images : with the filter it would be docker ps -aq --filter=image=busybox | xargs docker stop, without docker ps -a | grep busybox | awk '{ print $1 }' | xargs docker stop (but as seen in the previous point I could get false positive).

I do agree these are probably edge cases and might not happen a lot in real life or not that much but it felt so easy to implement.

I also do see potential on the "walk the ancestry tree" but I'm not sure how it would look in a user point of view. Question like :

  • Do I always want to walk the ancestry tree (and this, filtering on a base image would return all container running these or images based on it) or not ?
  • If not, how would I do to specify it needs to walk the tree or not ? (like --filter=image=debian&children)
  • Is there a real use case for that ? I don't know but maybe.

@duglin
Copy link
Contributor

duglin commented Jul 14, 2015

I only see the ancestry usecase as being interesting so no need for a flag to say "look at entire history", it should do it automagically.

@thaJeztah
Copy link
Member

I can see use cases for taking ancestry when filtering, but I really wonder if this is what I would expect if I filter name=foo. I think I would expect to only get containers started from foo. Perhaps another flag to include ancestry?

@thaJeztah
Copy link
Member

sorry name=foo should obviously be image=foo in my previous comment :-)

@duglin
Copy link
Contributor

duglin commented Jul 14, 2015

the reason I'm not sure "image=foo" is that interesting is because there isn't much of a difference between:

docker run -ti ubuntu some-command

and

docker build -f Dockerfile-FROM-ubuntu+some-command ...
docker run ...

I guess it might be a little useful to have: image=foo and ancestor=foo but I wonder how quickly people will opt for the ancestor variant once they realize they really want to look for more than the immediate parent image.

@thaJeztah
Copy link
Member

but I wonder how quickly people will opt for the ancestor variant once they realize they really want to look for more than the immediate parent image.

True, in many cases, either immediate parent or "uses" an image are what you're looking for. From a UX perspective though, I'm really against calling the "ancestor" filter "image", because it doesn't reflect the intent and will definitely lead to a lot of support questions / invalid bug reports.

We can opt for not implementing immediate parent (for now) and only implement ancestor search once people start asking for it. Perhaps an easier name for the filter, would "inherits" be a good name? --filter inherits=ubuntu:14.04

To the filtering itself, what kind of searches should be supported? A quick list;

  • image
  • image:tag
  • image:tag@digest
  • short-id
  • full-id

@cpuguy83
Copy link
Member

I definitely +1 to more filters.
Grep is nice, but not particularly nice in this case.

@vdemeester vdemeester force-pushed the 13365-ps-image-filter branch 8 times, most recently from d546941 to 39f9857 Compare July 31, 2015 08:02
@icecrime icecrime added the status/needs-attention Calls for a collective discussion during a review session label Aug 5, 2015
@tiborvass
Copy link
Contributor

Collective review

@duglin @calavera @tonistiigi

We would prefer the tree-traversal implementation instead of just filtering with a direct parent image name.

Because in the inspect output, Image refers to the direct parent image, we should not call the filter image, and we suggest ancestor instead (less ambiguous).

As for answering #14570 (comment), we should support all of the input forms. They will have to be mapped to a full image ID anyways.

Let's leave the "direct-parent-only" implementation for another time, as we seem to agree the tree-traversal is more useful.

@tiborvass tiborvass added status/2-code-review and removed status/1-design-review status/needs-attention Calls for a collective discussion during a review session labels Aug 6, 2015
@thaJeztah
Copy link
Member

SGTM, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

In the other test (below) you check for ancestors and immediate parent by ID, name, etc... but not digest. Here you're just checking for immediate parent by digest. I would hope checking for ancestor by digest would just work too, since its just another way to reference an image, but is it worth adding at least one check for "ancestor by digest" instead of just immediate parent?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah right, building an image from the imageReference and make sure we get the digested one and its descendant.

@duglin
Copy link
Contributor

duglin commented Aug 22, 2015

looks good, just one question.

@vdemeester vdemeester force-pushed the 13365-ps-image-filter branch from ecf3244 to 05f35f8 Compare August 24, 2015 20:52
@vdemeester
Copy link
Member Author

Oh I though I pushed the docs (which are quite small) but didn't.. 😅. /cc @thaJeztah

Copy link
Member

Choose a reason for hiding this comment

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

we probably should avoid using "image id" here, because the filter also accepts "image name", right?

Will need some examples, to illustrate/describe the possible options

Copy link
Member Author

Choose a reason for hiding this comment

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

@thaJeztah oh right, we should probably just add image (so it stays general) there and add more example in a Filtering chapter (as discussed a bit on IRC 😉)

@vdemeester vdemeester force-pushed the 13365-ps-image-filter branch from 05f35f8 to 0aa0f74 Compare August 24, 2015 21:45
@vdemeester
Copy link
Member Author

Updated with to take care of @duglin and @thaJeztah comments, I think 😅.

@thaJeztah
Copy link
Member

docs LGTM, as discussed with @vdemeester, examples will be added in a filtering chapter/section #14570 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

nit, s/container/image/

Copy link
Member Author

Choose a reason for hiding this comment

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

ah "oups" 😅

@duglin
Copy link
Contributor

duglin commented Aug 25, 2015

@vdemeester LGTM

@cpuguy83
Copy link
Member

Moving to docs review.

@thaJeztah
Copy link
Member

LGTM per my previous comment #14570 (comment)

Makes it possible to filter containers by image, using
--filter=ancestor=busybox and get all the container running busybox
image and image based on busybox (to the bottom).

Signed-off-by: Vincent Demeester <[email protected]>
@vdemeester vdemeester force-pushed the 13365-ps-image-filter branch from a49f36b to c1af0ac Compare August 26, 2015 21:00
@thaJeztah
Copy link
Member

ping @moxiegirl, looks like we merged the "follow up" before the one it's "following up" 😄

@vdemeester
Copy link
Member Author

@thaJeztah yay 😅 😝

@moxiegirl
Copy link
Contributor

This is why I should leave the merging to others (@thaJeztah) ...

@thaJeztah
Copy link
Member

@moxiegirl counting that as a LGTM, merging!

thaJeztah added a commit that referenced this pull request Aug 28, 2015
Add docker ps ancestor filter for image
@thaJeztah thaJeztah merged commit b1cb1b1 into moby:master Aug 28, 2015
@vdemeester
Copy link
Member Author

🎉 😉

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.

9 participants