Add before and since filter to images

Add support for two now filter on the `images` command : `before` and
`since`. They work the same as the one on the `ps` command but for
images.

        $ docker images --filter before=myimage
        # display all images older than myimage
        $ docker images --filter since=myimage
        # display all images younger than myimage

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2016-05-25 13:49:10 +02:00 committed by Tibor Vass
parent dd83546376
commit aac0a3ee13
4 changed files with 66 additions and 6 deletions

View File

@ -1104,6 +1104,11 @@ _docker_history() {
_docker_images() {
local key=$(__docker_map_key_of_current_option '--filter|-f')
case "$key" in
before)
cur="${cur##*=}"
__docker_complete_images
return
;;
dangling)
COMPREPLY=( $( compgen -W "false true" -- "${cur##*=}" ) )
return
@ -1111,11 +1116,16 @@ _docker_images() {
label)
return
;;
since)
cur="${cur##*=}"
__docker_complete_images
return
;;
esac
case "$prev" in
--filter|-f)
COMPREPLY=( $( compgen -S = -W "dangling label" -- "$cur" ) )
COMPREPLY=( $( compgen -S = -W "before dangling label since" -- "$cur" ) )
__docker_nospace
return
;;

View File

@ -341,10 +341,13 @@ __docker_complete_images_filters() {
declare -a boolean_opts opts
boolean_opts=('true' 'false')
opts=('dangling' 'label')
opts=('before' 'dangling' 'label' 'since')
if compset -P '*='; then
case "${${words[-1]%=*}#*=}" in
(before|since)
__docker_images && ret=0
;;
(dangling)
_describe -t boolean-filter-opts "filter options" boolean_opts && ret=0
;;

View File

@ -16,7 +16,11 @@ parent = "smn_cli"
-a, --all Show all images (default hides intermediate images)
--digests Show digests
-f, --filter=[] Filter output based on conditions provided
-f, --filter=[] Filter output based on these conditions:
- dangling=(true|false)
- label=<key> or label=<key>=<value>
- before=(<image-name>[:tag]|<image-id>|<image@digest>)
- since=(<image-name>[:tag]|<image-id>|<image@digest>)
--help Print usage
--no-trunc Don't truncate output
-q, --quiet Only show numeric IDs
@ -121,6 +125,8 @@ The currently supported filters are:
* dangling (boolean - true or false)
* label (`label=<key>` or `label=<key>=<value>`)
* before (`<image-name>[:<tag>]`, `<image id>` or `<image@digest>`) - filters images created before given id or references
* since (`<image-name>[:<tag>]`, `<image id>` or `<image@digest>`) - filters images created since given id or references
##### Untagged images (dangling)
@ -165,19 +171,56 @@ The following filter matches images with the `com.example.version` label regardl
REPOSITORY TAG IMAGE ID CREATED SIZE
match-me-1 latest eeae25ada2aa About a minute ago 188.3 MB
match-me-2 latest eeae25ada2aa About a minute ago 188.3 MB
match-me-2 latest dea752e4e117 About a minute ago 188.3 MB
The following filter matches images with the `com.example.version` label with the `1.0` value.
$ docker images --filter "label=com.example.version=1.0"
REPOSITORY TAG IMAGE ID CREATED SIZE
match-me latest eeae25ada2aa About a minute ago 188.3 MB
match-me latest 511136ea3c5a About a minute ago 188.3 MB
In this example, with the `0.1` value, it returns an empty set because no matches were found.
$ docker images --filter "label=com.example.version=0.1"
REPOSITORY TAG IMAGE ID CREATED SIZE
#### Before
The `before` filter shows only images created before the image with
given id or reference. For example, having these images:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
image1 latest eeae25ada2aa 4 minutes ago 188.3 MB
image2 latest dea752e4e117 9 minutes ago 188.3 MB
image3 latest 511136ea3c5a 25 minutes ago 188.3 MB
Filtering with `before` would give:
$ docker images --filter "before=image1"
REPOSITORY TAG IMAGE ID CREATED SIZE
image2 latest dea752e4e117 9 minutes ago 188.3 MB
image3 latest 511136ea3c5a 25 minutes ago 188.3 MB
#### Since
The `since` filter shows only images created after the image with
given id or reference. For example, having these images:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
image1 latest eeae25ada2aa 4 minutes ago 188.3 MB
image2 latest dea752e4e117 9 minutes ago 188.3 MB
image3 latest 511136ea3c5a 25 minutes ago 188.3 MB
Filtering with `since` would give:
$ docker images --filter "since=image3"
REPOSITORY TAG IMAGE ID CREATED SIZE
image1 latest eeae25ada2aa 4 minutes ago 188.3 MB
image2 latest dea752e4e117 9 minutes ago 188.3 MB
## Formatting
The formatting option (`--format`) will pretty print container output

View File

@ -38,7 +38,11 @@ versions.
Show image digests. The default is *false*.
**-f**, **--filter**=[]
Filters the output. The dangling=true filter finds unused images. While label=com.foo=amd64 filters for images with a com.foo value of amd64. The label=com.foo filter finds images with the label com.foo of any value.
Filters the output based on these conditions:
- dangling=(true|false) - finds unused images.
- label=<key> or label=<key>=<value>
- before=(<image-name>[:tag]|<image-id>|<image@digest>)
- since=(<image-name>[:tag]|<image-id>|<image@digest>)
**--format**="*TEMPLATE*"
Pretty-print containers using a Go template.