docker search命令的具体使用

Docker/容器
327
0
0
2023-08-07
标签   Docker
目录
  • 一、docker search 命令选项
  • 二、docker search 使用实例
  • 2.1 通过指定镜像名搜索
  • 2.2 搜索结果不进行截断显示
  • 2.3 设置搜索结果只显示10个
  • 2.4 搜索结果过滤star收藏数量大于等于3个
  • 2.5 搜索结果只列出自动构建的镜像
  • 2.6 搜索结果只列出官方镜像
  • 2.7 搜索结果通过多个条件过滤
  • 2.8 定制自定义打印输出格式

一、docker search 命令选项

命令选项

描述

–filter , -f

根据给定的条件进行过滤

–format

自定义打印格式

–limit

显示搜索结果,默认值25

–no-trunc

回显结果不进行截断,全部显示

二、docker search 使用实例

2.1 通过指定镜像名搜索

[root@redrose ~]# docker search busybox
NAME                                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
busybox                             Busybox base image.      [OK]
radial/busyboxplus                  Full-chain, Internet enabled, busybox made f…                   [OK]
yauritux/busybox-curl               Busybox with CURL
armv7/busybox                     Busybox base image.                             10
armv8/busybox                     Busybox base image.                             4
odise/busybox-curl                    [OK]
i/busybox                        Busybox base image.                             3
pppc64/busybox                     Busybox base image for ppc64.                   2
sx/busybox                       Busybox base image.                             2
prom/busybox                        Prometheus Busybox Docker base images                    [OK]
busybox/zimbra-docker-centos      A Zimbra Docker image, based in ZCS 8.8.9 an…   2                    [OK]
joeshaw/busybox-nonroot             Busybox container with non-root user nobody
vukomir/busybox                     busybox and curl
spotify/busybox                     Spotify fork of https://hub.docker.com/_/bus…
busybox/haraka-docker-centos      CentOS Haraka build with spamassassin, redis…   1                    [OK]
ppcle/busybox                     Busybox base image.                             1
amd/busybox                       Busybox base image.                             1
busybox/nginx_php-docker-centos   This is a nginx/php-fpm server running on Ce…   1                    [OK]
ibmcom/busybox-ppcle                                                              0
busybox/alpine-pod                                                                0
antrea/busybox
openebs/busybox-client
ibmcom/busybox
rancher/busybox
ibmcom/busybox-amd                                                                0
[root@redrose ~]#

2.2 搜索结果不进行截断显示

[root@redrose ~]# docker search busybox --no-trunc
NAME                                DESCRIPTION                                                                                 STARS     OFFICIAL   AUTOMATED
busybox                             Busybox base image.      [OK]
radial/busyboxplus                  Full-chain, Internet enabled, busybox made from scratch. Comes in git and cURL flavors.                   [OK]
yauritux/busybox-curl               Busybox with CURL
armv7/busybox                     Busybox base image.                                                                         10
odise/busybox-curl                    [OK]
armv8/busybox                     Busybox base image.                                                                         4
i/busybox                        Busybox base image.                                                                         3
pppc64/busybox                     Busybox base image for ppc64.                                                               2
sx/busybox                       Busybox base image.                                                                         2
prom/busybox                        Prometheus Busybox Docker base images                    [OK]
busybox/zimbra-docker-centos      A Zimbra Docker image, based in ZCS 8.8.9 and CentOS 7.                                     2                    [OK]
joeshaw/busybox-nonroot             Busybox container with non-root user nobody
vukomir/busybox                     busybox and curl
spotify/busybox                     Spotify fork of https://hub.docker.com/_/busybox/ for testing helios.
busybox/haraka-docker-centos      CentOS Haraka build with spamassassin, redis and some other things.  Experimental still..   1                    [OK]
ppcle/busybox                     Busybox base image.                                                                         1
amd/busybox                       Busybox base image.                                                                         1
busybox/nginx_php-docker-centos   This is a nginx/php-fpm server running on CentOS 7.                                         1                    [OK]
ibmcom/busybox-ppcle                                                                                                          0
antrea/busybox
busybox/alpine-pod                                                                                                            0
openebs/busybox-client
ibmcom/busybox
rancher/busybox
ibmcom/busybox-amd                                                                                                            0
[root@redrose ~]#

2.3 设置搜索结果只显示10个

[root@redrose ~]# docker search busybox --limit=10
NAME                     DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
busybox                  Busybox base image.      [OK]
radial/busyboxplus       Full-chain, Internet enabled, busybox made f…                   [OK]
yauritux/busybox-curl    Busybox with CURL
vukomir/busybox          busybox and curl
antrea/busybox
ibmcom/busybox-amd                                                     0
ibmcom/busybox-ppcle                                                   0
rancher/busybox
ibmcom/busybox
openebs/busybox-client
[root@redrose ~]#

2.4 搜索结果过滤star收藏数量大于等于3个

[root@redrose ~]# docker search busybox --filter stars=3
NAME                    DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
busybox                 Busybox base image.      [OK]
radial/busyboxplus      Full-chain, Internet enabled, busybox made f…                   [OK]
yauritux/busybox-curl   Busybox with CURL
armv7/busybox         Busybox base image.                             10
odise/busybox-curl                    [OK]
armv8/busybox         Busybox base image.                             4
i/busybox            Busybox base image.                             3
[root@redrose ~]#

2.5 搜索结果只列出自动构建的镜像

[root@redrose ~]# docker search busybox --filter is-automated=true
NAME                                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
radial/busyboxplus                  Full-chain, Internet enabled, busybox made f…                   [OK]
odise/busybox-curl                    [OK]
busybox/zimbra-docker-centos      A Zimbra Docker image, based in ZCS 8.8.9 an…   2                    [OK]
prom/busybox                        Prometheus Busybox Docker base images                    [OK]
busybox/haraka-docker-centos      CentOS Haraka build with spamassassin, redis…   1                    [OK]
busybox/nginx_php-docker-centos   This is a nginx/php-fpm server running on Ce…   1                    [OK]
[root@redrose ~]#

2.6 搜索结果只列出官方镜像

[root@redrose ~]# docker search busybox --filter is-official=true
NAME      DESCRIPTION           STARS     OFFICIAL   AUTOMATED
busybox   Busybox base image.      [OK]
[root@redrose ~]#

2.7 搜索结果通过多个条件过滤

如下为过滤自动构建的并且收藏数量大于等于3的镜像

[root@redrose ~]# docker search busybox --filter is-automated=true --filter stars=3
NAME                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
radial/busyboxplus   Full-chain, Internet enabled, busybox made f…                   [OK]
odise/busybox-curl                    [OK]
[root@redrose ~]#

2.8 定制自定义打印输出格式

docker search 可以通过 --format 参数定制自定义打印格式,可自定义的占位字段如下:

占位符

描述

.Name

镜像名称

.Description

镜像描述

.StarCount

镜像被收藏数量

.IsOfficial

镜像是否为官方镜像,如果是现实“OK”

.IsAutomated

镜像是否为自动构建,如果是显示“OK”

如下为搜索nginx镜像,只显示镜像名称和镜像被收藏数量

[root@redrose ~]# docker search --format "{{.Name}}: {{.StarCount}}" nginx
nginx:
linuxserver/nginx:
bitnami/nginx:
ubuntu/nginx:
bitnami/nginx-ingress-controller:
rancher/nginx-ingress-controller:
webdevops/nginx:
ibmcom/nginx-ingress-controller:
bitnami/nginx-ldap-auth-daemon:
rancher/nginx:
kasmweb/nginx:
vmware/nginx:
rancher/nginx-ingress-controller-defaultbackend:
rapidfort/nginx:
bitnami/nginx-exporter:
wallarm/nginx-ingress-controller:
vmware/nginx-photon:
bitnami/nginx-intel:
rapidfort/nginx-ib:
ibmcom/nginx-ingress-controller-ppcle: 0
rancher/nginx-conf:
rancher/nginx-ssl:
continuumio/nginx-ingress-ws:
rancher/nginx-ingress-controller-amd: 0
ibmcom/nginx-ppcle: 0
[root@redrose ~]#

如下,格式化显示镜像名称、镜像被收藏数量、镜像是否自动构建、镜像是否官方

[root@redrose ~]# docker search --format "table {{.Name}}\t\t{{.StarCount}}\t\t{{.IsAutomated}}\t\t{{.IsOfficial}}" nginx
NAME                                                        STARS               AUTOMATED             OFFICIAL
nginx                                     [OK]
linuxserver/nginx
bitnami/nginx                 [OK]
ubuntu/nginx
bitnami/nginx-ingress-controller                  [OK]
rancher/nginx-ingress-controller
webdevops/nginx                  [OK]
ibmcom/nginx-ingress-controller
bitnami/nginx-ldap-auth-daemon
rancher/nginx
kasmweb/nginx
vmware/nginx
rancher/nginx-ingress-controller-defaultbackend
rapidfort/nginx
bitnami/nginx-exporter
wallarm/nginx-ingress-controller
vmware/nginx-photon
bitnami/nginx-intel
rapidfort/nginx-ib
rancher/nginx-conf
ibmcom/nginx-ingress-controller-ppcle                     0
rancher/nginx-ssl
continuumio/nginx-ingress-ws
rancher/nginx-ingress-controller-amd                      0
ibmcom/nginx-ppcle                                        0
[root@redrose ~]#