使用 docker help 命令查看 docker images 命令的帮助信息,如下:
[root@localhost ~]# 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 numeric IDs
其中:
-a, --all 显示所有的镜像,默认隐藏中间镜像层
--digests 显示摘要,一串十六进制字符串,如MD5消息摘要
-f, --filter filter 根据提供的条件过滤输出
--format string 使用Go模板打印漂亮的镜像
--no-trunc 不截断输出,输出完整的镜像信息
-q, --quiet 只显示数字ID
实例1:显示本机docker上面的镜像,如下:
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE myimage latest 99a68c0f45ff 24 hours ago 202MB redis latest 598a6f110d01 5 days ago 118MB tomcat9 latest 2619ee45e83f 7 days ago 916MB ubuntu latest 4c108a37151f 4 weeks ago 64.2MB centos latest 9f38484d220f 4 months ago 202MB
其中:
REPOSITORY:表示镜像的仓库源
TAG:镜像的标签
IMAGE_ID:镜像ID
CREATED:镜像创建时间
SIZE:镜像大小
同一仓库源可以有多个TAG,代表这个仓库源的不同个版本,我们使用 REPOSITORY:TAG 来定义不同的镜像。如果你不指定一个镜像的版本标签,例如你只使用 ubuntu,docker 将默认使用ubuntu:latest 镜像。
实例2:查看指定的镜像,下面将直接查看 ubuntu 镜像的 latest 版本镜像信息。如下:
[root@localhost ~]# docker images ubuntu REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 4c108a37151f 4 weeks ago 64.2MB
实例3:使用 -q 选项查看指定的 docker 镜像的ID,然后我们可以根据该ID批量删除镜像。下面使用“docker images”查看当前docker镜像列表,如下:
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE myimage latest 99a68c0f45ff 24 hours ago 202MB redis latest 598a6f110d01 5 days ago 118MB tomcat9 latest 2619ee45e83f 7 days ago 916MB ubuntu latest 4c108a37151f 4 weeks ago 64.2MB centos latest 9f38484d220f 4 months ago 202MB
然后使用“docker rmi $(docker images -q)”命令批量删除镜像。如下:
[root@localhost ~]# docker rmi $(docker images -q) Error response from daemon: conflict: unable to delete 99a68c0f45ff (must be forced) - image is being used by stopped container a203e0ca18d9 Error response from daemon: conflict: unable to delete 598a6f110d01 (must be forced) - image is being used by stopped container 35732ecdd9d9 Error response from daemon: conflict: unable to delete 2619ee45e83f (must be forced) - image is being used by stopped container 3f0594d6cde9 Error response from daemon: conflict: unable to delete 4c108a37151f (must be forced) - image is being used by stopped container cd5b845cf72f Error response from daemon: conflict: unable to delete 9f38484d220f (cannot be forced) - image has dependent child images
上面执行的命令抛出了错误,这是因为镜像有容器在使用,不能删除,需要使用 -f 强制删除。如下:
[root@localhost ~]# docker rmi $(docker images -q) -f Untagged: myimage:latest Deleted: sha256:99a68c0f45ffdb98dd0389e179d4af44b2ba390c12f4bd57b21b30824852cb43 Deleted: sha256:3a782dfda07e34c2031a06663204c80ea02116702dfac0ca7e9a1aa98e19c918 Untagged: redis:latest Untagged: redis@sha256:74ee482ee42e7acb000e7fc5f32d292fc056464403834b0790a6e46175ff3ff5 Deleted: sha256:598a6f110d01ba2d8086011cf70571b4a52a532e25189a70042171ed9d700b50 Untagged: tomcat9:latest Deleted: sha256:2619ee45e83f1363266d6c1447ad78f0f4df2f0375fd1f62b098f19826dc0056 Deleted: sha256:5740e6bcb807ec726a038a4dcfdfae934df6eb9c9e3a2df67233091f67503cdb Deleted: sha256:b1809ccfbedadc087131259560568ca64516620ef62e83af87d661e515f84c9f Deleted: sha256:dedd306660ce0b42ba33a857b0799c4dd471e878039e1f91cc2f49e48f094e0c Deleted: sha256:ef484938826ff0de3c594f2d8d0f5ccf54860bf3f3e078b5cfa4b93020d4d25b Deleted: sha256:4c44e8c93b97e03d4366448ac867170f32e3f007d90b349776693a764f7d0dd8 Deleted: sha256:497cbba7548726f34236a70d343d735bc5ae94da61d259dc86837279034cdff1 Deleted: sha256:0668f8a9f0010a6d1d16713314bc13bdef37b23b6bb5185c312ac5b74b626b6d Deleted: sha256:a8fc032fe78b62f2f5e97d77ab6b87a91aefde2c2df292f3a975b1bea995ba58 Deleted: sha256:e88d9fb84bcd05157e1a602746b3f1acb50968e1a78322c714861d38fb317e1e Deleted: sha256:215720ff5c7aff6a0b56a9b560268a3c4ab974267d6698c3233c25a71fda472c Deleted: sha256:d9079b92bfabd395c4a13cb5f57fad42ec30ed9489bdb82ab00f1769770de4c7 Deleted: sha256:0eea6afa060b0f10f0eeb031969b827c6bbbebe71cef4b781fa2098ce74f05dc Deleted: sha256:3afbe94bccd2ee5d722a866e3844ebbd92211bf1eb71fad17ec7dc75ebb9b583 Deleted: sha256:8cd1a6e0430e9b30b48b9a187074da00593b6f37ecd7f20891e685579f8651d4 Untagged: ubuntu:latest Untagged: ubuntu@sha256:9b1702dcfe32c873a770a32cfd306dd7fc1c4fd134adfb783db68defc8894b3c Deleted: sha256:4c108a37151f54439950335c409802e948883e00c93fdb751d206c9a9674c1f6 Untagged: centos:latest Untagged: centos@sha256:a799dd8a2ded4a83484bbae769d97655392b3f86533ceb7dd96bbac929809f3c Deleted: sha256:9f38484d220fa527b1fb19747638497179500a1bed8bf0498eb788229229e6e1 [root@localhost ~]#