点击学习开源企业 Docker 镜像仓库 Harbor 软件 教程。
在 Docker 中,使用 docker image ls 命令列出本地已有的镜像。
语法如下:
用法: docker image ls [OPTIONS] [REPOSITORY[:TAG]] 列出镜像 别名: docker image ls, docker image list, docker images 选项: -a、--all 显示所有镜像(默认隐藏中间镜像) --digests 显示摘要 -f、--filter filter 根据提供的条件过滤输出 --format string 使用自定义模板格式化输出: 'table':以带列头的表格格式打印输出(默认值) 'table TEMPLATE':使用给定的 Go 模板以表格格式打印输出 'json':以 JSON 格式打印 'TEMPLATE':使用给定的 Go 模板以表格格式打印输出 有关使用模板格式化输出的更多信息,请参阅 https://docs.docker.com/go/formatting/。 --no-trunc 不截断输出 -q、--quiet 只显示镜像ID
(1)显示所有的镜像列表
root@hxstrive:~# docker image ls -a REPOSITORY TAG IMAGE ID CREATED SIZE redis latest dae83f665c92 3 weeks ago 117MB mysql latest 7ce93a845a8a 4 weeks ago 586MB mongo latest a31b196b207d 7 weeks ago 796MB nginx latest 900dca2a61f5 2 months ago 188MB
或者
root@hxstrive:~# docker image ls --all REPOSITORY TAG IMAGE ID CREATED SIZE redis latest dae83f665c92 3 weeks ago 117MB mysql latest 7ce93a845a8a 4 weeks ago 586MB mongo latest a31b196b207d 7 weeks ago 796MB nginx latest 900dca2a61f5 2 months ago 188MB
(2)显示镜像摘要信息
root@hxstrive:~# docker image ls --digests REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE redis latest sha256:e30eac723e308f27e92cb609024b6be3ed2b2fb67899ec37043f743b169e17a5 dae83f665c92 3 weeks ago 117MB mysql latest sha256:d8df069848906979fd7511db00dc22efeb0a33a990d87c3c6d3fcdafd6fc6123 7ce93a845a8a 4 weeks ago 586MB mongo latest sha256:d672a079266a48faee269e6b5c6b1c7b9d9de3ddd8a1d5097a0881e15576bbb4 a31b196b207d 7 weeks ago 796MB nginx latest sha256:81dbf3ecf1120d90ace4593096bb650a2d11d4a11d24c3aaea5bef7c9bbb2c88 900dca2a61f5 2 months ago 188MB
(3)使用指定的格式输出镜像列表
root@hxstrive:~# docker image ls --format table REPOSITORY TAG IMAGE ID CREATED SIZE redis latest dae83f665c92 3 weeks ago 117MB mysql latest 7ce93a845a8a 4 weeks ago 586MB mongo latest a31b196b207d 7 weeks ago 796MB nginx latest 900dca2a61f5 2 months ago 188MB
或者
root@hxstrive:~# docker image ls --format json {"Containers":"N/A","CreatedAt":"2024-07-29 15:59:06 +0800 CST","CreatedSince":"3 weeks ago","Digest":"\u003cnone\u003e","ID":"dae83f665c92","Repository":"redis","SharedSize":"N/A","Size":"117MB","Tag":"latest","UniqueSize":"N/A","VirtualSize":"116.9MB"} {"Containers":"N/A","CreatedAt":"2024-07-23 06:36:10 +0800 CST","CreatedSince":"4 weeks ago","Digest":"\u003cnone\u003e","ID":"7ce93a845a8a","Repository":"mysql","SharedSize":"N/A","Size":"586MB","Tag":"latest","UniqueSize":"N/A","VirtualSize":"585.7MB"} {"Containers":"N/A","CreatedAt":"2024-06-29 06:05:28 +0800 CST","CreatedSince":"7 weeks ago","Digest":"\u003cnone\u003e","ID":"a31b196b207d","Repository":"mongo","SharedSize":"N/A","Size":"796MB","Tag":"latest","UniqueSize":"N/A","VirtualSize":"795.9MB"} {"Containers":"N/A","CreatedAt":"2024-06-21 10:12:35 +0800 CST","CreatedSince":"2 months ago","Digest":"\u003cnone\u003e","ID":"900dca2a61f5","Repository":"nginx","SharedSize":"N/A","Size":"188MB","Tag":"latest","UniqueSize":"N/A","VirtualSize":"187.6MB"}
(4)只输出镜像的 ID
root@hxstrive:~# docker image ls -q dae83f665c92 7ce93a845a8a a31b196b207d 900dca2a61f5
(5)根据特定的条件过滤列出的镜像。
a、根据镜像名称过滤
root@hxstrive:~# docker image ls -f "reference=nginx" REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 900dca2a61f5 2 months ago 188MB nginx 1.20 0584b370e957 2 years ago 141MB nginx 1.19 f0b8a9a54136 3 years ago 133MB nginx 1.18 c2c45d506085 3 years ago 133MB
这个命令会列出所有名称中包含nginx的镜像。
b、 根据镜像创建时间过滤
root@hxstrive:~# docker image ls -f "before=nginx:latest" REPOSITORY TAG IMAGE ID CREATED SIZE nginx 1.20 0584b370e957 2 years ago 141MB nginx 1.19 f0b8a9a54136 3 years ago 133MB nginx 1.18 c2c45d506085 3 years ago 133MB
这将列出所有创建时间在nginx:latest镜像创建时间之前的镜像。
root@hxstrive:~# docker image ls -f "since=nginx:latest" REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest 70dd81c409f9 2 weeks ago 461MB redis latest dae83f665c92 3 weeks ago 117MB mysql latest 7ce93a845a8a 4 weeks ago 586MB mongo latest a31b196b207d 7 weeks ago 796MB
则会列出所有创建时间在 nginx:latest 镜像创建时间之后的镜像。
点击学习开源企业 Docker 镜像仓库 Harbor 软件 教程。