docker 命令images

2020-06-23  本文已影响0人  老柿子

该命令用于列举本地的镜像,其中还有本地命令的一些操作有如下,都是用来在本地做处理使用的

用法:

Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]

List images

Options:
  -a, --all                 Show all images (default hides intermediate images)
  --digests                 Show digests
  -f, --filter filter   Filter output based on conditions provided
  --format string           Pretty-print images using a Go template
  --no-trunc                Don't truncate output
  -q, --quiet               Only show numeric IDs

示例:

docker images java

直接展示了repository为java的镜像

docker images -a

展示本地的所有镜像,默认隐藏中间的镜像

zhouzhenyong@shizi-2 ~/tem> docker images -a
REPOSITORY                      TAG                                              IMAGE ID            CREATED             SIZE
test/isc-panda                  1.0.0                                            942d4dd9eb3c        10 hours ago        177MB
<none>                          <none>                                           7e6256d9d5f0        10 hours ago        177MB
<none>                          <none>                                           e134476eee5f        10 hours ago        177MB
<none>                          <none>                                           d3d69ab0ab27        10 hours ago        177MB
<none>                          <none>                                           314010f38f7b        10 hours ago        177MB
<none>                          <none>                                           efebccec952b        10 hours ago        177MB
<none>                          <none>                                           450e15c7459f        10 hours ago        177MB
<none>                          <none>                                           bd615cd2dd18        10 hours ago        177MB
<none>                          <none>                                           96ae66cb0553        10 hours ago        177MB
<none>                          <none>                                           f28ebb70bbc9        10 hours ago        177MB

docker images --digests

展示镜像的摘要

zhouzhenyong@shizi-2 ~/tem> docker images --digests
REPOSITORY         TAG       DIGEST         IMAGE ID            CREATED             SIZE
test/isc-panda     1.0.0     <none>         942d4dd9eb3c        10 hours ago        177MB
<none>             <none>    <none>         450e15c7459f        10 hours ago        177MB
<none>             <none>    <none>         96ae66cb0553        10 hours ago        177MB

docker images -f xxxx

查看对应的过滤条件,这个过滤标签的格式是 “key=value”,如果有多个条件,则使用这种 --filter "key1=value" --filter "key2=value"。比如:过滤没有打标签的镜像

docker images -f "dangling=true"

zhouzhenyong@shizi-2 ~/tem> docker images -f "dangling=true"
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              450e15c7459f        10 hours ago        177MB
<none>              <none>              96ae66cb0553        10 hours ago        177MB
<none>              <none>              a05eb601e28c        10 hours ago        177MB
<none>              <none>              402ba2565be1        10 hours ago        177MB
<none>              <none>              d76f78b54042        11 hours ago        177MB
<none>              <none>              0f98eccb4a62        12 hours ago        177MB
<none>              <none>              56423d65f24f        22 hours ago        177MB
<none>              <none>              3c553f44e156        22 hours ago        177MB
<none>              <none>              644627b7fb2e        22 hours ago        177MB

当前支持的过滤配置的key为

docker images -f "dangling=true"

表示清理当前repo:tag为<none>的镜像。在对应的镜像repo:tag构建新的镜像的时候,旧的镜像就会从repo:tag中移走,进而成为<none>,这个时候,我们就可以对这些进行清理

docker rmi $(docker images -f "dangling=true" -q)

docker images -f "before=mysql"

表示在mysql:latest之前的构建的镜像

zhouzhenyong@shizi-2 ~> docker images -f "before=mysql"
Error response from daemon: No such image: mysql:latest
zhouzhenyong@shizi-2 ~> docker images -f "before=mysql:8.0.20"
REPOSITORY                      TAG                                              IMAGE ID            CREATED             SIZE
docker/desktop-kubernetes       kubernetes-v1.16.5-cni-v0.7.5-critools-v1.15.0   a86647f0b376        5 months ago        279MB
docker/kube-compose-installer   v0.4.25-alpha1                                   2a71ac5a1359        7 months ago        42.3MB
golang                          1.11-alpine                                      e116d2efa2ab        10 months ago       312MB
openjdk                         8-jdk-alpine                                     a3562aa0b991        13 months ago       105MB

docker images -f=reference=':'

zhouzhenyong@shizi-2 ~> docker images --filter=reference='*:*'
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               8.0.20              be0dbf01a0f3        13 days ago         541MB
golang              1.11-alpine         e116d2efa2ab        10 months ago       312MB
openjdk             8-jdk-alpine        a3562aa0b991        13 months ago       105MB

docker images --format

这个是进行对展示的进行格式化话展示

Placeholder Description
.ID Image ID
.Repository Image repository
.Tag Image tag
.Digest Image digest
.CreatedSince Elapsed time since the image was created
.CreatedAt Time when the image was created
.Size Image disk size
zhouzhenyong@shizi-2 ~> docker images --format "{{.ID}}\t{{.Repository}}"
942d4dd9eb3c    test/isc-panda
450e15c7459f    <none>
644627b7fb2e    <none>
b3f353ae77d2    simonalong/isc-panda
d30e0389349f    simonalong/cheers2019
be0dbf01a0f3    mysql
a86647f0b376    docker/desktop-kubernetes
2a71ac5a1359    docker/kube-compose-installer
e116d2efa2ab    golang
a3562aa0b991    openjdk

docker images -q

这个其实跟 docker images --format "{{.ID}}" 效果是一样的,是只展示ID

zhouzhenyong@shizi-2 ~> docker images --format "{{.ID}}"
942d4dd9eb3c
450e15c7459f
644627b7fb2e
b3f353ae77d2
d30e0389349f
be0dbf01a0f3
a86647f0b376
2a71ac5a1359
e116d2efa2ab
a3562aa0b991
zhouzhenyong@shizi-2 ~> docker images -q
942d4dd9eb3c
450e15c7459f
644627b7fb2e
b3f353ae77d2
d30e0389349f
be0dbf01a0f3
a86647f0b376
2a71ac5a1359
e116d2efa2ab
a3562aa0b991

参考:

https://www.simapple.com/326.html
https://docs.docker.com/engine/reference/commandline/images/

上一篇下一篇

猜你喜欢

热点阅读