Add a --filter option to docker search

The filtering is made server-side, and the following filters are
supported:

* is-official (boolean)
* is-automated (boolean)
* has-stars (integer)

Signed-off-by: Fabrizio Soppelsa <fsoppelsa@mirantis.com>
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Fabrizio Soppelsa
2016-05-20 13:41:28 +02:00
committed by Vincent Demeester
parent 0e9009bae3
commit e009ebdf4c
12 changed files with 272 additions and 49 deletions

View File

@@ -58,6 +58,15 @@ defining it at container creation (`POST /containers/create`).
The `docker ps --before` and `docker ps --since` options are deprecated.
Use `docker ps --filter=before=...` and `docker ps --filter=since=...` instead.
### Docker search 'automated' and 'stars' options
**Deprecated in Release: [v1.12.0](https://github.com/docker/docker/releases/tag/v1.12.0)**
**Removed In Release: v1.14**
The `docker search --automated` and `docker search --stars` options are deprecated.
Use `docker search --filter=is-automated=...` and `docker search --filter=stars=...` instead.
### Command line short variant options
**Deprecated In Release: v1.9**

View File

@@ -118,6 +118,7 @@ This section lists each version from latest to oldest. Each listing includes a
* `POST /containers/create` now takes `MaximumIOps` and `MaximumIOBps` fields. Windows daemon only.
* `POST /containers/create` now returns a HTTP 400 "bad parameter" message
if no command is specified (instead of a HTTP 500 "server error")
* `GET /images/search` now takes a `filters` query parameter.
### v1.23 API changes

View File

@@ -2133,6 +2133,10 @@ Search for an image on [Docker Hub](https://hub.docker.com).
Query Parameters:
- **term** term to search
- **filters** a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters:
- `stars=<number>`
- `is-automated=(true|false)`
- `is-official=(true|false)`
Status Codes:

View File

@@ -14,10 +14,12 @@ parent = "smn_cli"
Search the Docker Hub for images
--automated Only show automated builds
--filter=[] Filter output based on these conditions:
- is-automated=(true|false)
- is-official=(true|false)
- stars=<number> - image has at least 'number' stars
--help Print usage
--no-trunc Don't truncate output
-s, --stars=0 Only displays with at least x stars
Search [Docker Hub](https://hub.docker.com) for images
@@ -61,29 +63,6 @@ This example displays images with a name containing 'busybox':
scottabernethy/busybox 0 [OK]
marclop/busybox-solr
### Search images by name and number of stars (-s, --stars)
This example displays images with a name containing 'busybox' and at
least 3 stars:
$ docker search --stars=3 busybox
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
busybox Busybox base image. 325 [OK]
progrium/busybox 50 [OK]
radial/busyboxplus Full-chain, Internet enabled, busybox made... 8 [OK]
### Search automated images (--automated)
This example displays images with a name containing 'busybox', at
least 3 stars and are automated builds:
$ docker search --stars=3 --automated busybox
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
progrium/busybox 50 [OK]
radial/busyboxplus Full-chain, Internet enabled, busybox made... 8 [OK]
### Display non-truncated description (--no-trunc)
This example displays images with a name containing 'busybox',
@@ -95,3 +74,48 @@ at least 3 stars and the description isn't truncated in the output:
progrium/busybox 50 [OK]
radial/busyboxplus Full-chain, Internet enabled, busybox made from scratch. Comes in git and cURL flavors. 8 [OK]
## Filtering
The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there is more
than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`)
The currently supported filters are:
* stars (int - number of stars the image has)
* is-automated (true|false) - is the image automated or not
* is-official (true|false) - is the image official or not
### stars
This example displays images with a name containing 'busybox' and at
least 3 stars:
$ docker search --filter stars=3 busybox
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
busybox Busybox base image. 325 [OK]
progrium/busybox 50 [OK]
radial/busyboxplus Full-chain, Internet enabled, busybox made... 8 [OK]
### is-automated
This example displays images with a name containing 'busybox'
and are automated builds:
$ docker search --filter is-automated busybox
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
progrium/busybox 50 [OK]
radial/busyboxplus Full-chain, Internet enabled, busybox made... 8 [OK]
### is-official
This example displays images with a name containing 'busybox', at least
3 stars and are official builds:
$ docker search --filter "is-automated=true" --filter "stars=3" busybox
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
progrium/busybox 50 [OK]
radial/busyboxplus Full-chain, Internet enabled, busybox made... 8 [OK]