該命令用於列舉本地的鏡像,其中還有本地命令的一些操作有如下,都是用來在本地做處理使用的
用法:
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爲
- dangling:顯示標記爲空的鏡像,值只有true和false
- label:這個是根據標籤進行過濾,其中lable的值,是docker在編譯的時候配置的或者在Dockerfile中配置的
- before:這個是根據時間來進行過濾,其中before的value表示某個鏡像構建時間之前的鏡像列表
- since:跟before正好相反,表示的是在某個鏡像構建之後構建的鏡像
- reference:這個是添加正則進行匹配
docker images -f “dangling=true”
表示清理當前repo:tag爲的鏡像。在對應的鏡像repo:tag構建新的鏡像的時候,舊的鏡像就會從repo:tag中移走,進而成爲,這個時候,我們就可以對這些進行清理
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/