文章目录

  • 一、docker images 命令选项
  • 二、docker images 使用实例
  • 2.1 显示最近创建的镜像
  • 2.2 根据镜像名和tag值查询
  • 2.3 查询结果中显示完整的镜像ID
  • 2.4 显示镜像的摘要信息
  • 2.5 显示未打tag值的镜像
  • 2.6 删除未打tag值额镜像
  • 2.7 根据标签筛选镜像
  • 2.8 根据时间筛选镜像
  • 2.9 通过模糊匹配筛选镜像
  • 2.10 自定义打印格式


一、docker images 命令选项

选项

作用

–all , -a

显示所有镜像(默认情况下中间镜像不会显示)

–digests

显示镜像摘要信息

–filter , -f

根据给定条件筛选镜像

–format

指定自定义打印格式

–no-trunc

显示完整的镜像ID

–quiet , -q

只显示镜像ID

二、docker images 使用实例

2.1 显示最近创建的镜像

[root@redrose2100 ~]# docker images
REPOSITORY                                                          TAG               IMAGE ID       CREATED             SIZE
harbor.redrose2100.com/redrose2100/blog                             20220923_124634   b4d4f9107532   About an hour ago   1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220923_122444   7ac9f98bfd7a   About an hour ago   1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220923_091848   a1f59d789247   5 hours ago         1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220922_212506   611667eded7d   16 hours ago        1.08GB
[root@redrose2100 ~]#

2.2 根据镜像名和tag值查询

如下为根据镜像名称查询

[root@redrose2100 ~]# docker images python
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
python       3.9       81f391f1a7d7   9 months ago   912MB
python       3.10      a5d7930b60cc   9 months ago   917MB
[root@redrose2100 ~]#

如下为根据镜像名和tag值查询

[root@redrose2100 ~]# docker images python:3.9
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
python       3.9       81f391f1a7d7   9 months ago   912MB
[root@redrose2100 ~]#

如下,当本地镜像不存在时,列表显示为空

[root@redrose2100 ~]# docker images java
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@redrose2100 ~]#

2.3 查询结果中显示完整的镜像ID

[root@redrose2100 ~]# docker images --no-trunc
REPOSITORY                                                          TAG               IMAGE ID                                                                  CREATED             SIZE
harbor.redrose2100.com/redrose2100/blog                             20220923_124634   sha256:b4d4f9107532143defc572bfcba40a323664278471845cb37be0314f38a3b447   About an hour ago   1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220923_122444   sha256:7ac9f98bfd7a614b8e85f3ee7f49d59193f268fbdcd852ffd1463281986e8b01   2 hours ago         1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220923_091848   sha256:a1f59d7892470617f2344ae05165e3ccd8f483cf7b9e78de80d63203679e90a7   5 hours ago         1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220922_212506   sha256:611667eded7d643eef23641aab5e903d0d31b5000d9dc44c8f3c4a69e3b816c3   17 hours ago        1.08GB
[root@redrose2100 ~]#

2.4 显示镜像的摘要信息

[root@redrose2100 ~]# docker images --digests
python                                                              3.9               sha256:c0dcc146710fed0a6d62cb55b92f00bfbfc3b931fff6218f4958bab58333c37b   81f391f1a7d7   9 months ago        912MB
python                                                              3.10              sha256:dbbfcbf95f6b596d2be1d8f3b368016619f78f829facf6f2e361bea1151794e5   a5d7930b60cc   9 months ago        917MB
[root@redrose2100 ~]#

2.5 显示未打tag值的镜像

[root@redrose2100 ~]# docker images --filter="dangling=true"
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
<none>       <none>    2865aa315916   2 weeks ago   203MB
[root@redrose2100 ~]#

2.6 删除未打tag值额镜像

[root@redrose2100 ~]# docker rmi -f $(docker images --filter="dangling=true" -q)
Deleted: sha256:2865aa3159164dcbc1fd9aaffc9d8ef888d82cc3c79b6de4f01276276effdc62
Deleted: sha256:4a6e84f553ce40ea1205fe7f80491bea9e1d109d90af648dc954e69650a281c4
[root@redrose2100 ~]#

2.7 根据标签筛选镜像

如下为查询打了com.example.version标签的镜像

docker search怎么确定image的架构_git


如下为查询打了com.example.version标签,并且标签的值为1.0的镜像

docker search怎么确定image的架构_linux_02


如下为查询打了com.example.version标签,并且标签的值为0.1的镜像,结果显示没有

docker search怎么确定image的架构_python_03

2.8 根据时间筛选镜像

首先查看一下当前环境上所有的镜像

[root@redrose2100 ~]# docker images
REPOSITORY                                                          TAG               IMAGE ID       CREATED         SIZE
harbor.redrose2100.com/redrose2100/blog                             20220923_124634   b4d4f9107532   2 hours ago     1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220923_122444   7ac9f98bfd7a   3 hours ago     1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220923_091848   a1f59d789247   6 hours ago     1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220922_212506   611667eded7d   18 hours ago    1.08GB
demo                                                                v1.0              0d9ec139222a   2 months ago    1.07GB
goharbor/redis-photon                                               v2.5.3            5dc5331f3de8   2 months ago    154MB
goharbor/harbor-registryctl                                         v2.5.3            942de6829d43   2 months ago    136MB
goharbor/registry-photon                                            v2.5.3            fb1278854b91   2 months ago    77.9MB
goharbor/nginx-photon                                               v2.5.3            91877cbc147a   2 months ago    44.3MB
goharbor/harbor-log                                                 v2.5.3            ca36fb3b68a6   2 months ago    161MB
goharbor/harbor-jobservice                                          v2.5.3            75e6a7496590   2 months ago    227MB
goharbor/harbor-core                                                v2.5.3            93a775677473   2 months ago    203MB
goharbor/harbor-portal                                              v2.5.3            d78f9bbad9ee   2 months ago    52.6MB
goharbor/harbor-db                                                  v2.5.3            bd50ae1eccdf   2 months ago    224MB
goharbor/prepare                                                    v2.5.3            15102b9ebde6   2 months ago    166MB
harbor.redrose2100.com/redrose2100/blog                             20220704_094433   e103d5596ed5   2 months ago    1.07GB
registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper   x86_64-5316d4ac   30da8020e87a   4 months ago    71.9MB
jianmudev/jianmu-ci-ui                                              v2.3.1            cdb50d58c752   4 months ago    137MB
jianmudev/jianmu-ci-server                                          v2.3.1            c8a35aa002d0   4 months ago    564MB
docker.elastic.co/kibana/kibana                                     8.1.3             6bccb01e35af   5 months ago    736MB
docker.elastic.co/elasticsearch/elasticsearch                       8.1.3             b543e34fe3ca   5 months ago    1.2GB
jianmurunner/ssh_cmd                                                1.0.1             af9edcc3b231   8 months ago    12.1MB
gitlab/gitlab-ce                                                    latest            46cd6954564a   8 months ago    2.36GB
easysoft/zentao                                                     latest            bbba77b62d94   8 months ago    699MB
redis                                                               latest            7614ae9453d1   9 months ago    113MB
python                                                              3.9               81f391f1a7d7   9 months ago    912MB
python                                                              3.10              a5d7930b60cc   9 months ago    917MB
mysql                                                               5.7               c20987f18b13   9 months ago    448MB
mysql                                                               8                 3218b38490ce   9 months ago    516MB
gitlab/gitlab-runner                                                latest            77a7b2f30dd5   9 months ago    700MB
docker                                                              latest            15a9bc7c6340   9 months ago    216MB
jianmurunner/custom_node_example                                    1.0.0-shell       df318473d03e   9 months ago    76.3MB
jenkins/jenkins                                                     lts               2a4bbe50c40b   9 months ago    441MB
openeuler/openeuler                                                 21.09             e8fb1a00da37   11 months ago   202MB
ubuntu                                                              18.04             5a214d77f5d7   11 months ago   63.1MB
centos                                                              latest            5d0da3dc9764   12 months ago   231MB
centos                                                              7.8.2003          afb6fca791e0   2 years ago     203MB
vuldocker/lamp                                                      latest            c0d193876aff   2 years ago     615MB
fellah/gitbook                                                      latest            29087de21915   6 years ago     287MB
acgpiano/sqli-labs                                                  latest            0976afc45249   6 years ago     434MB
[root@redrose2100 ~]#

如下为查询ubuntu镜像z之前的镜像

[root@redrose2100 ~]# docker images --filter="before=ubuntu:18.04"
REPOSITORY           TAG        IMAGE ID       CREATED         SIZE
centos               latest     5d0da3dc9764   12 months ago   231MB
centos               7.8.2003   afb6fca791e0   2 years ago     203MB
vuldocker/lamp       latest     c0d193876aff   2 years ago     615MB
fellah/gitbook       latest     29087de21915   6 years ago     287MB
acgpiano/sqli-labs   latest     0976afc45249   6 years ago     434MB
[root@redrose2100 ~]#

如下则为查询redis镜像之后的镜像

[root@redrose2100 ~]# docker images --filter="since=redis:latest"
REPOSITORY                                                          TAG               IMAGE ID       CREATED        SIZE
harbor.redrose2100.com/redrose2100/blog                             20220923_124634   b4d4f9107532   2 hours ago    1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220923_122444   7ac9f98bfd7a   3 hours ago    1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220923_091848   a1f59d789247   6 hours ago    1.08GB
harbor.redrose2100.com/redrose2100/blog                             20220922_212506   611667eded7d   18 hours ago   1.08GB
demo                                                                v1.0              0d9ec139222a   2 months ago   1.07GB
goharbor/redis-photon                                               v2.5.3            5dc5331f3de8   2 months ago   154MB
goharbor/harbor-registryctl                                         v2.5.3            942de6829d43   2 months ago   136MB
goharbor/registry-photon                                            v2.5.3            fb1278854b91   2 months ago   77.9MB
goharbor/nginx-photon                                               v2.5.3            91877cbc147a   2 months ago   44.3MB
goharbor/harbor-log                                                 v2.5.3            ca36fb3b68a6   2 months ago   161MB
goharbor/harbor-jobservice                                          v2.5.3            75e6a7496590   2 months ago   227MB
goharbor/harbor-core                                                v2.5.3            93a775677473   2 months ago   203MB
goharbor/harbor-portal                                              v2.5.3            d78f9bbad9ee   2 months ago   52.6MB
goharbor/harbor-db                                                  v2.5.3            bd50ae1eccdf   2 months ago   224MB
goharbor/prepare                                                    v2.5.3            15102b9ebde6   2 months ago   166MB
harbor.redrose2100.com/redrose2100/blog                             20220704_094433   e103d5596ed5   2 months ago   1.07GB
registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper   x86_64-5316d4ac   30da8020e87a   4 months ago   71.9MB
jianmudev/jianmu-ci-ui                                              v2.3.1            cdb50d58c752   4 months ago   137MB
jianmudev/jianmu-ci-server                                          v2.3.1            c8a35aa002d0   4 months ago   564MB
docker.elastic.co/kibana/kibana                                     8.1.3             6bccb01e35af   5 months ago   736MB
docker.elastic.co/elasticsearch/elasticsearch                       8.1.3             b543e34fe3ca   5 months ago   1.2GB
jianmurunner/ssh_cmd                                                1.0.1             af9edcc3b231   8 months ago   12.1MB
gitlab/gitlab-ce                                                    latest            46cd6954564a   8 months ago   2.36GB
easysoft/zentao                                                     latest            bbba77b62d94   8 months ago   699MB
[root@redrose2100 ~]#

2.9 通过模糊匹配筛选镜像

通过模糊匹配需要使用reference 过滤器,如下为匹配镜像名以py开头,tag值以3开头的镜像

[root@redrose2100 ~]# docker images --filter=reference="py*:3*"
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
python       3.9       81f391f1a7d7   9 months ago   912MB
python       3.10      a5d7930b60cc   9 months ago   917MB
[root@redrose2100 ~]#

如下为使用连个filter进行过滤的用法,这种方式只要匹配一个即被筛选。

[root@redrose2100 ~]# docker images  --filter=reference="my*" --filter=reference="py*:3*"
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
python       3.9       81f391f1a7d7   9 months ago   912MB
python       3.10      a5d7930b60cc   9 months ago   917MB
mysql        5.7       c20987f18b13   9 months ago   448MB
mysql        8         3218b38490ce   9 months ago   516MB
[root@redrose2100 ~]#

此外这里需要注意的是斜线是不能被*号匹配的,如下:

[root@redrose2100 ~]# docker images  --filter=reference="go*"
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@redrose2100 ~]# docker images  --filter=reference="go*/*"
REPOSITORY                    TAG       IMAGE ID       CREATED        SIZE
goharbor/redis-photon         v2.5.3    5dc5331f3de8   2 months ago   154MB
goharbor/harbor-registryctl   v2.5.3    942de6829d43   2 months ago   136MB
goharbor/registry-photon      v2.5.3    fb1278854b91   2 months ago   77.9MB
goharbor/nginx-photon         v2.5.3    91877cbc147a   2 months ago   44.3MB
goharbor/harbor-log           v2.5.3    ca36fb3b68a6   2 months ago   161MB
goharbor/harbor-jobservice    v2.5.3    75e6a7496590   2 months ago   227MB
goharbor/harbor-core          v2.5.3    93a775677473   2 months ago   203MB
goharbor/harbor-portal        v2.5.3    d78f9bbad9ee   2 months ago   52.6MB
goharbor/harbor-db            v2.5.3    bd50ae1eccdf   2 months ago   224MB
goharbor/prepare              v2.5.3    15102b9ebde6   2 months ago   166MB
[root@redrose2100 ~]#

2.10 自定义打印格式

自定义打印格式支持指定的字段如下:

字段

描述

.ID

镜像 ID

.Repository

镜像名

.Tag

镜像的tag

.Digest

镜像摘要

.CreatedSince

创建的时间跨度

.CreatedAt

创建时间点

.Size

镜像磁盘大小

如下为只显示镜像ID和镜像名

[root@redrose2100 ~]# docker images --format "{{.ID}}: {{.Repository}}"
b4d4f9107532: harbor.redrose2100.com/redrose2100/blog
7ac9f98bfd7a: harbor.redrose2100.com/redrose2100/blog
a1f59d789247: harbor.redrose2100.com/redrose2100/blog
611667eded7d: harbor.redrose2100.com/redrose2100/blog
0d9ec139222a: demo
5dc5331f3de8: goharbor/redis-photon
942de6829d43: goharbor/harbor-registryctl
fb1278854b91: goharbor/registry-photon
91877cbc147a: goharbor/nginx-photon
ca36fb3b68a6: goharbor/harbor-log
75e6a7496590: goharbor/harbor-jobservice
93a775677473: goharbor/harbor-core
d78f9bbad9ee: goharbor/harbor-portal
bd50ae1eccdf: goharbor/harbor-db
15102b9ebde6: goharbor/prepare
e103d5596ed5: harbor.redrose2100.com/redrose2100/blog
30da8020e87a: registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper
cdb50d58c752: jianmudev/jianmu-ci-ui
c8a35aa002d0: jianmudev/jianmu-ci-server
6bccb01e35af: docker.elastic.co/kibana/kibana
b543e34fe3ca: docker.elastic.co/elasticsearch/elasticsearch
af9edcc3b231: jianmurunner/ssh_cmd
46cd6954564a: gitlab/gitlab-ce
bbba77b62d94: easysoft/zentao
7614ae9453d1: redis
81f391f1a7d7: python
a5d7930b60cc: python
c20987f18b13: mysql
3218b38490ce: mysql
77a7b2f30dd5: gitlab/gitlab-runner
15a9bc7c6340: docker
df318473d03e: jianmurunner/custom_node_example
2a4bbe50c40b: jenkins/jenkins
e8fb1a00da37: openeuler/openeuler
5a214d77f5d7: ubuntu
5d0da3dc9764: centos
afb6fca791e0: centos
c0d193876aff: vuldocker/lamp
29087de21915: fellah/gitbook
0976afc45249: acgpiano/sqli-labs
[root@redrose2100 ~]#

如下为只打印镜像ID和镜像名,并且以表格的形式打印,所谓以表格的形式就是存在表头标题等,如下

[root@redrose2100 ~]# docker images --format "table {{.ID}}: {{.Repository}}"
IMAGE ID: REPOSITORY
b4d4f9107532: harbor.redrose2100.com/redrose2100/blog
7ac9f98bfd7a: harbor.redrose2100.com/redrose2100/blog
a1f59d789247: harbor.redrose2100.com/redrose2100/blog
611667eded7d: harbor.redrose2100.com/redrose2100/blog
0d9ec139222a: demo
5dc5331f3de8: goharbor/redis-photon
942de6829d43: goharbor/harbor-registryctl
fb1278854b91: goharbor/registry-photon
91877cbc147a: goharbor/nginx-photon
ca36fb3b68a6: goharbor/harbor-log
75e6a7496590: goharbor/harbor-jobservice
93a775677473: goharbor/harbor-core
d78f9bbad9ee: goharbor/harbor-portal
bd50ae1eccdf: goharbor/harbor-db
15102b9ebde6: goharbor/prepare
e103d5596ed5: harbor.redrose2100.com/redrose2100/blog
30da8020e87a: registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper
cdb50d58c752: jianmudev/jianmu-ci-ui
c8a35aa002d0: jianmudev/jianmu-ci-server
6bccb01e35af: docker.elastic.co/kibana/kibana
b543e34fe3ca: docker.elastic.co/elasticsearch/elasticsearch
af9edcc3b231: jianmurunner/ssh_cmd
46cd6954564a: gitlab/gitlab-ce
bbba77b62d94: easysoft/zentao
7614ae9453d1: redis
81f391f1a7d7: python
a5d7930b60cc: python
c20987f18b13: mysql
3218b38490ce: mysql
77a7b2f30dd5: gitlab/gitlab-runner
15a9bc7c6340: docker
df318473d03e: jianmurunner/custom_node_example
2a4bbe50c40b: jenkins/jenkins
e8fb1a00da37: openeuler/openeuler
5a214d77f5d7: ubuntu
5d0da3dc9764: centos
afb6fca791e0: centos
c0d193876aff: vuldocker/lamp
29087de21915: fellah/gitbook
0976afc45249: acgpiano/sqli-labs
[root@redrose2100 ~]#