docker筛选容器和镜像

偏向技术
/ 0 评论 / 216 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年08月06日,已超过1016天没有更新,若内容或图片失效,请留言反馈。

镜像

powershell
❯ docker images --help

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 image IDs
12345678910111213

通过 -a / --all可以筛选出所有状态下的镜像,--digests 可以显示出镜像摘要,--filter 筛选过滤,--format 格式化输出列表展示,--no-trunc 指明不要截断输出

以下通过实际例子说明每个属性的作用,以下面这些镜像为例:

powershell
❯ docker images
REPOSITORY                                                 TAG            IMAGE ID       CREATED             SIZE
<none>                                                     <none>         c15f6a08bd05   40 minutes ago      1.88GB
fun-cache-76648a02-c217-405f-a6a8-decedfff08ad             latest         efbc773a6539   About an hour ago   2.23GB
fun-cache-e88ba098-4fbb-4cc9-a2af-d02645ae638d             latest         efbc773a6539   About an hour ago   2.23GB
fun-cache-28165075-9239-4b53-bf32-41009cdf15c0             latest         efbc773a6539   About an hour ago   2.23GB
fun-cache-405a0602-8113-4601-b831-0651e5e168ea             latest         efbc773a6539   About an hour ago   2.23GB
fun-cache-57689e27-3785-49e1-96be-5080dcad2739             latest         5dc92562f89c   About an hour ago   2.23GB
fun-cache-9337c1e2-2c10-4ed4-b52a-b8b2e8e9dc20             latest         5dc92562f89c   About an hour ago   2.23GB
fun-cache-193beceb-19dd-4ca8-a268-efbe6ecc37c1             latest         a804b7f3b816   2 hours ago         2.23GB
fun-cache-657bbdcb-e324-47e6-adbd-92c396e982aa             latest         a804b7f3b816   2 hours ago         2.23GB
aliyunfc/runtime-custom                                    1.9.17         1aa5c8035675   4 months ago        1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   1.9.17         1aa5c8035675   4 months ago        1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   build-1.9.17   e6282033ae8d   4 months ago        1.88GB
centos                                                     latest         300e315adb2f   8 months ago        209MB
123456789101112131415

显示所有 -a / --all

显示所有镜像

powershell
❯ docker images -a
REPOSITORY                                                 TAG            IMAGE ID       CREATED        SIZE
<none>                                                     <none>         c15f6a08bd05   3 hours ago    1.88GB
fun-cache-28165075-9239-4b53-bf32-41009cdf15c0             latest         efbc773a6539   4 hours ago    2.23GB
fun-cache-405a0602-8113-4601-b831-0651e5e168ea             latest         efbc773a6539   4 hours ago    2.23GB
fun-cache-76648a02-c217-405f-a6a8-decedfff08ad             latest         efbc773a6539   4 hours ago    2.23GB
fun-cache-e88ba098-4fbb-4cc9-a2af-d02645ae638d             latest         efbc773a6539   4 hours ago    2.23GB
<none>                                                     <none>         1475f6ee67fc   4 hours ago    2.23GB
<none>                                                     <none>         8ea0f54444e1   4 hours ago    2.23GB
<none>                                                     <none>         3ebd594c5a05   4 hours ago    2.23GB
<none>                                                     <none>         ac7b100bf4ea   4 hours ago    2.23GB
<none>                                                     <none>         81a778d24435   4 hours ago    2.04GB
<none>                                                     <none>         b8e7f428e1bc   4 hours ago    2.04GB
<none>                                                     <none>         c099173b3d86   4 hours ago    2.04GB
<none>                                                     <none>         79c0700b9311   4 hours ago    1.92GB
fun-cache-57689e27-3785-49e1-96be-5080dcad2739             latest         5dc92562f89c   4 hours ago    2.23GB
fun-cache-9337c1e2-2c10-4ed4-b52a-b8b2e8e9dc20             latest         5dc92562f89c   4 hours ago    2.23GB
1234567891011121314151617

显示摘要 --digests

powershell
❯ docker images --digests
REPOSITORY                                                 TAG            DIGEST
               IMAGE ID       CREATED        SIZE
<none>                                                     <none>         <none>
               c15f6a08bd05   3 hours ago    1.88GB
fun-cache-e88ba098-4fbb-4cc9-a2af-d02645ae638d             latest         <none>
               efbc773a6539   4 hours ago    2.23GB
fun-cache-28165075-9239-4b53-bf32-41009cdf15c0             latest         <none>
               efbc773a6539   4 hours ago    2.23GB
fun-cache-405a0602-8113-4601-b831-0651e5e168ea             latest         <none>
               efbc773a6539   4 hours ago    2.23GB
fun-cache-76648a02-c217-405f-a6a8-decedfff08ad             latest         <none>
               efbc773a6539   4 hours ago    2.23GB
fun-cache-57689e27-3785-49e1-96be-5080dcad2739             latest         <none>
               5dc92562f89c   4 hours ago    2.23GB
fun-cache-9337c1e2-2c10-4ed4-b52a-b8b2e8e9dc20             latest         <none>
               5dc92562f89c   4 hours ago    2.23GB
fun-cache-193beceb-19dd-4ca8-a268-efbe6ecc37c1             latest         <none>
               a804b7f3b816   4 hours ago    2.23GB
fun-cache-657bbdcb-e324-47e6-adbd-92c396e982aa             latest         <none>
               a804b7f3b816   4 hours ago    2.23GB
ubuntu                                                     latest         sha256:82becede498899ec668628e7cb0ad87b6e1c371cb8a1e597d83a47fac21d6af3   1318b700e415   10 days ago    72.8MB
aliyunfc/runtime-custom                                    1.9.17         <none>
               1aa5c8035675   4 months ago   1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   1.9.17         sha256:8c47d7956a4038a17b6c4a8f660e341b35152f8b623544fe3ae6c3bc3d7ee7dc   1aa5c8035675   4 months ago   1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   build-1.9.17   sha256:91c378a1024872ea74372a4af127c5bb0d5ddd650848adc3cc5eed7625fab465   e6282033ae8d   4 months ago   1.88GB
centos                                                     latest         sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1   300e315adb2f   8 months ago   209MB
centos                                                     7              sha256:0f4ec88e21daf75124b8a9e5ca03c37a5e937e0e108a255d890492430789b60e   8652b9f0cb4c   8 months ago   204MB
12345678910111213141516171819202122232425262728

筛选过滤 -f / --filter

  1. dangling:显示标记为空的镜像,布尔值,true和false
  2. label: (label=<key> or label=<key>=<value>)根据标签进行过滤,其中lable的值,是docker在编译的时候配置的或者在Dockerfile中配置的
  3. before:(<image-name>[:<tag>], <image id> or <image@digest>),根据时间来进行过滤,其中before的value表示某个镜像构建时间之前的镜像列表
  4. since:(<image-name>[:<tag>], <image id> or <image@digest>),跟before正好相反,表示的是在某个镜像构建之后构建的镜像
  5. reference:添加正则进行匹配

dangling

筛选出为空的镜像,合法值为 truefalse ,不合法将会给出错误提示

powershell
❯ docker images -f "dangling=true"
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
<none>       <none>    c15f6a08bd05   41 minutes ago   1.88GB
123
powershell
❯ docker images -f "dangling=false"
REPOSITORY                                                 TAG            IMAGE ID       CREATED             SIZE
fun-cache-28165075-9239-4b53-bf32-41009cdf15c0             latest         efbc773a6539   About an hour ago   2.23GB
fun-cache-405a0602-8113-4601-b831-0651e5e168ea             latest         efbc773a6539   About an hour ago   2.23GB
fun-cache-76648a02-c217-405f-a6a8-decedfff08ad             latest         efbc773a6539   About an hour ago   2.23GB
fun-cache-e88ba098-4fbb-4cc9-a2af-d02645ae638d             latest         efbc773a6539   About an hour ago   2.23GB
fun-cache-57689e27-3785-49e1-96be-5080dcad2739             latest         5dc92562f89c   About an hour ago   2.23GB
fun-cache-9337c1e2-2c10-4ed4-b52a-b8b2e8e9dc20             latest         5dc92562f89c   About an hour ago   2.23GB
fun-cache-193beceb-19dd-4ca8-a268-efbe6ecc37c1             latest         a804b7f3b816   2 hours ago         2.23GB
fun-cache-657bbdcb-e324-47e6-adbd-92c396e982aa             latest         a804b7f3b816   2 hours ago         2.23GB
aliyunfc/runtime-custom                                    1.9.17         1aa5c8035675   4 months ago        1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   1.9.17         1aa5c8035675   4 months ago        1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   build-1.9.17   e6282033ae8d   4 months ago        1.88GB
centos                                                     latest         300e315adb2f   8 months ago        209MB
1234567891011121314
powershell
❯ docker images -f "dangling=fals"
Error response from daemon: Invalid filter 'dangling=[fals]'
12

label

格式为 label=<key> or label=<key>=<value>,以centos镜像为例:

拉取镜像,并添加了两个自己设置的label,"my-label"和"com.example.foo=bar"

powershell
❯ docker run -l my-label --label com.example.foo=bar -it centos /bin/bash
1

此时,我们仅能通过这两个label来筛选容器,无法用来筛选镜像

powershell
❯ docker ps -f "label=my-label"   
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
4d147d620d8a   centos    "/bin/bash"   6 seconds ago   Up 5 seconds             happy_booth
123

筛选镜像的话需要用到镜像本身绑定的label,通过grep筛选出centos镜像自身的label

powershell
❯ docker inspect centos | grep label
                "org.label-schema.build-date": "20201204",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
                "org.label-schema.build-date": "20201204",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
1234567891011

通过centos镜像自身的label可以用来筛选容器和镜像,以"org.label-schema.vendor": "CentOS"为例

powershell
❯ docker ps -f "label=org.label-schema.vendor=CentOS"
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS        PORTS     NAMES
12e8575c7304   centos    "/bin/bash"   2 seconds ago   Up 1 second             sweet_goodall
123
powershell
❯ docker images -f "label=org.label-schema.vendor=CentOS"
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    300e315adb2f   8 months ago   209MB
123

before

筛选出从匹配镜像开始之前的镜像,即列表下,匹配镜像下面的镜像,格式为:<image-name>[:<tag>], <image id> or <image@digest>,当 <tag>latest 时可省略

powershell
❯ docker images -f "before=fun-cache-657bbdcb-e324-47e6-adbd-92c396e982aa"
REPOSITORY                                                 TAG            IMAGE ID       CREATED        SIZE
aliyunfc/runtime-custom                                    1.9.17         1aa5c8035675   4 months ago   1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   1.9.17         1aa5c8035675   4 months ago   1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   build-1.9.17   e6282033ae8d   4 months ago   1.88GB
centos                                                     latest         300e315adb2f   8 months ago   209MB
123456

从下面的筛选列表可以看出镜像 aliyunfc/runtime-customregistry.cn-beijing.aliyuncs.com/aliyunfc/runtime-customTAG 都为 1.9.17 ,当使用 aliyunfc/runtime-custom:1.9.17 进行筛选,其实匹配到的是 registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom 镜像,当匹配到同名同TAG的镜像时,选择最后匹配(从上往下最后)到的一个

powershell
❯ docker images -f "before=aliyunfc/runtime-custom:1.9.17"
REPOSITORY                                                 TAG            IMAGE ID       CREATED        SIZE
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   build-1.9.17   e6282033ae8d   4 months ago   1.88GB
centos                                                     latest         300e315adb2f   8 months ago   209MB
1234

since

筛选出从匹配镜像开始之后的镜像,即列表下,匹配镜像上面的镜像,格式为:<image-name>[:<tag>], <image id> or <image@digest><tag>latest 时可省略

powershell
❯ docker images -f "since=aliyunfc/runtime-custom:1.9.17"
REPOSITORY                                       TAG       IMAGE ID       CREATED             SIZE
<none>                                           <none>    c15f6a08bd05   About an hour ago   1.88GB
fun-cache-28165075-9239-4b53-bf32-41009cdf15c0   latest    efbc773a6539   2 hours ago         2.23GB
fun-cache-405a0602-8113-4601-b831-0651e5e168ea   latest    efbc773a6539   2 hours ago         2.23GB
fun-cache-76648a02-c217-405f-a6a8-decedfff08ad   latest    efbc773a6539   2 hours ago         2.23GB
fun-cache-e88ba098-4fbb-4cc9-a2af-d02645ae638d   latest    efbc773a6539   2 hours ago         2.23GB
fun-cache-57689e27-3785-49e1-96be-5080dcad2739   latest    5dc92562f89c   2 hours ago         2.23GB
fun-cache-9337c1e2-2c10-4ed4-b52a-b8b2e8e9dc20   latest    5dc92562f89c   2 hours ago         2.23GB
fun-cache-193beceb-19dd-4ca8-a268-efbe6ecc37c1   latest    a804b7f3b816   3 hours ago         2.23GB
fun-cache-657bbdcb-e324-47e6-adbd-92c396e982aa   latest    a804b7f3b816   3 hours ago         2.23GB
1234567891011

从下面的筛选列表可以看出镜像 registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-customTAG1.9.17 ,当使用 registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom 进行筛选,其实匹配到的是 aliyunfc/runtime-custom 镜像,当匹配到同名同TAG的镜像时,选择最后匹配(从下往上最后)到的一个

powershell
❯ docker images -f "since=registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom:1.9.17"
REPOSITORY                                       TAG       IMAGE ID       CREATED             SIZE
<none>                                           <none>    c15f6a08bd05   About an hour ago   1.88GB
fun-cache-e88ba098-4fbb-4cc9-a2af-d02645ae638d   latest    efbc773a6539   2 hours ago         2.23GB
fun-cache-28165075-9239-4b53-bf32-41009cdf15c0   latest    efbc773a6539   2 hours ago         2.23GB
fun-cache-405a0602-8113-4601-b831-0651e5e168ea   latest    efbc773a6539   2 hours ago         2.23GB
fun-cache-76648a02-c217-405f-a6a8-decedfff08ad   latest    efbc773a6539   2 hours ago         2.23GB
fun-cache-57689e27-3785-49e1-96be-5080dcad2739   latest    5dc92562f89c   2 hours ago         2.23GB
fun-cache-9337c1e2-2c10-4ed4-b52a-b8b2e8e9dc20   latest    5dc92562f89c   2 hours ago         2.23GB
fun-cache-193beceb-19dd-4ca8-a268-efbe6ecc37c1   latest    a804b7f3b816   3 hours ago         2.23GB
fun-cache-657bbdcb-e324-47e6-adbd-92c396e982aa   latest    a804b7f3b816   3 hours ago         2.23GB
1234567891011

reference

reference通过正则匹配来筛选镜像,同样可以匹配<image-name>[:<tag>]<image@digest>,但是需要注意的是,通配符 * 无法匹配 /. 符号,以centoscentos:7为例

powershell
❯ docker images --filter=reference='centos'
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    300e315adb2f   8 months ago   209MB
centos       7         8652b9f0cb4c   8 months ago   204MB
1234
powershell
❯ docker images --filter=reference='centos:7'
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       7         8652b9f0cb4c   8 months ago   204MB
123

查看digest,为了能够看清,我们通过 --format 来格式化输出内容

powershell
❯ docker images --format "{{.Repository}}    {{.Digest}}"
<none>    <none>
fun-cache-76648a02-c217-405f-a6a8-decedfff08ad    <none>
fun-cache-e88ba098-4fbb-4cc9-a2af-d02645ae638d    <none>
fun-cache-28165075-9239-4b53-bf32-41009cdf15c0    <none>
fun-cache-405a0602-8113-4601-b831-0651e5e168ea    <none>
fun-cache-57689e27-3785-49e1-96be-5080dcad2739    <none>
fun-cache-9337c1e2-2c10-4ed4-b52a-b8b2e8e9dc20    <none>
fun-cache-193beceb-19dd-4ca8-a268-efbe6ecc37c1    <none>
fun-cache-657bbdcb-e324-47e6-adbd-92c396e982aa    <none>
ubuntu    sha256:82becede498899ec668628e7cb0ad87b6e1c371cb8a1e597d83a47fac21d6af3
aliyunfc/runtime-custom    <none>
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom    sha256:8c47d7956a4038a17b6c4a8f660e341b35152f8b623544fe3ae6c3bc3d7ee7dc
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom    sha256:91c378a1024872ea74372a4af127c5bb0d5ddd650848adc3cc5eed7625fab465
centos    sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
centos    sha256:0f4ec88e21daf75124b8a9e5ca03c37a5e937e0e108a255d890492430789b60e
12345678910111213141516

实际筛选如下:

powershell
❯ docker images "centos@*"
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       <none>    300e315adb2f   8 months ago   209MB
centos       <none>    8652b9f0cb4c   8 months ago   204MB
1234
powershell
❯ docker images "centos@sha256:*"
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       <none>    300e315adb2f   8 months ago   209MB
centos       <none>    8652b9f0cb4c   8 months ago   204MB
1234
powershell
❯ docker images "centos@sha256:0f*"
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       <none>    8652b9f0cb4c   8 months ago   204MB
123

通配符匹配:

通过下面的匹配,可以看出 aliyunfc/runtime-customregistry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom两个镜像是没有出现在下面列表的

powershell
❯ docker images --filter=reference="*"
REPOSITORY                                       TAG       IMAGE ID       CREATED        SIZE
fun-cache-e88ba098-4fbb-4cc9-a2af-d02645ae638d   latest    efbc773a6539   3 hours ago    2.23GB
fun-cache-28165075-9239-4b53-bf32-41009cdf15c0   latest    efbc773a6539   3 hours ago    2.23GB
fun-cache-405a0602-8113-4601-b831-0651e5e168ea   latest    efbc773a6539   3 hours ago    2.23GB
fun-cache-76648a02-c217-405f-a6a8-decedfff08ad   latest    efbc773a6539   3 hours ago    2.23GB
fun-cache-57689e27-3785-49e1-96be-5080dcad2739   latest    5dc92562f89c   4 hours ago    2.23GB
fun-cache-9337c1e2-2c10-4ed4-b52a-b8b2e8e9dc20   latest    5dc92562f89c   4 hours ago    2.23GB
fun-cache-193beceb-19dd-4ca8-a268-efbe6ecc37c1   latest    a804b7f3b816   4 hours ago    2.23GB
fun-cache-657bbdcb-e324-47e6-adbd-92c396e982aa   latest    a804b7f3b816   4 hours ago    2.23GB
ubuntu                                           latest    1318b700e415   10 days ago    72.8MB
centos                                           latest    300e315adb2f   8 months ago   209MB
centos                                           7         8652b9f0cb4c   8 months ago   204MB
12345678910111213
powershell
❯ docker images --filter=reference="fun*"
REPOSITORY                                       TAG       IMAGE ID       CREATED       SIZE
fun-cache-405a0602-8113-4601-b831-0651e5e168ea   latest    efbc773a6539   3 hours ago   2.23GB
fun-cache-76648a02-c217-405f-a6a8-decedfff08ad   latest    efbc773a6539   3 hours ago   2.23GB
fun-cache-e88ba098-4fbb-4cc9-a2af-d02645ae638d   latest    efbc773a6539   3 hours ago   2.23GB
fun-cache-28165075-9239-4b53-bf32-41009cdf15c0   latest    efbc773a6539   3 hours ago   2.23GB
fun-cache-57689e27-3785-49e1-96be-5080dcad2739   latest    5dc92562f89c   4 hours ago   2.23GB
fun-cache-9337c1e2-2c10-4ed4-b52a-b8b2e8e9dc20   latest    5dc92562f89c   4 hours ago   2.23GB
fun-cache-193beceb-19dd-4ca8-a268-efbe6ecc37c1   latest    a804b7f3b816   4 hours ago   2.23GB
fun-cache-657bbdcb-e324-47e6-adbd-92c396e982aa   latest    a804b7f3b816   4 hours ago   2.23GB
12345678910

如果要匹配 registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom 镜像,需要使用下面的方式

powershell
❯ docker images --filter=reference="*.*.*.*/*/*"
REPOSITORY                                                 TAG            IMAGE ID       CREATED        SIZE
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   1.9.17         1aa5c8035675   4 months ago   1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   build-1.9.17   e6282033ae8d   4 months ago   1.88GB
1234

重置格式 --format

通过 --format 我们可以筛选出自己需要的内容

  1. .ID:` 镜像ID
  2. .Repository: 镜像仓库名称
  3. .Tag: 镜像标签tag
  4. .Digest: 镜像摘要
  5. .CreatedSince: 距离创建时间经过了多久
  6. .CreatedAt: 镜像创建时间
  7. .Size: 镜像大小
powershell
❯ docker images --format "{{.ID}}  {{.Repository}} {{.Size}}"
c15f6a08bd05  <none> 1.88GB
efbc773a6539  fun-cache-28165075-9239-4b53-bf32-41009cdf15c0 2.23GB
efbc773a6539  fun-cache-405a0602-8113-4601-b831-0651e5e168ea 2.23GB
efbc773a6539  fun-cache-76648a02-c217-405f-a6a8-decedfff08ad 2.23GB
efbc773a6539  fun-cache-e88ba098-4fbb-4cc9-a2af-d02645ae638d 2.23GB
5dc92562f89c  fun-cache-57689e27-3785-49e1-96be-5080dcad2739 2.23GB
5dc92562f89c  fun-cache-9337c1e2-2c10-4ed4-b52a-b8b2e8e9dc20 2.23GB
a804b7f3b816  fun-cache-657bbdcb-e324-47e6-adbd-92c396e982aa 2.23GB
a804b7f3b816  fun-cache-193beceb-19dd-4ca8-a268-efbe6ecc37c1 2.23GB
1318b700e415  ubuntu 72.8MB
1aa5c8035675  registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom 1.45GB
1aa5c8035675  aliyunfc/runtime-custom 1.45GB
e6282033ae8d  registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom 1.88GB
300e315adb2f  centos 209MB
8652b9f0cb4c  centos 204MB
12345678910111213141516

容器

主要用法和镜像差不多

powershell
❯ docker ps --help

Usage:  docker ps [OPTIONS]

List containers

Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers (includes all
                        states) (default -1)
  -l, --latest          Show the latest created container (includes all
                        states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display container IDs
  -s, --size            Display total file sizes
1234567891011121314151617

实际应用

1. 删除REPOSITORY为none的镜像

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

2. 根据名称删除镜像

powershell
# 查看单个筛选也可以聚合筛选
❯ docker images -a -f reference="fun*" -f reference="aliyunfc/*" -f reference="*.*.*.*/aliyunfc/*"
REPOSITORY                                                 TAG            IMAGE ID       CREATED          SIZE
fun-cache-625f37a8-d6b1-48a6-9e55-e38dddd9416b             latest         0aad74e040fa   13 minutes ago   2.23GB
fun-cache-277b5083-eba0-40ab-a7ed-478889e946dd             latest         0aad74e040fa   13 minutes ago   2.23GB
aliyunfc/runtime-custom                                    1.9.17         1aa5c8035675   4 months ago     1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   1.9.17         1aa5c8035675   4 months ago     1.45GB
registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom   build-1.9.17   e6282033ae8d   4 months ago     1.88GB

# 删除语句
docker rmi $(docker images -a -f reference="fun*" -f reference="aliyunfc/*" -f reference="*.*.*.*/aliyunfc/*" -q) -f
1234567891011
0

评论 (0)

取消