如何删除Docker映像

Docker uses images in order to start new container. New containers will use existing images and adds new layers for the customized parts. In this tutorial we will look how to manage docker images.

Docker使用映像来启动新容器。 新容器将使用现有图像,并为自定义零件添加新层。 在本教程中,我们将研究如何管理Docker映像。

列出Docker映像 (List Docker Images)

Before removing Docker Images we generally need to list these images. We will use list command in order to list currently existing Docker Images.

在删除Docker映像之前,我们通常需要列出这些映像。 我们将使用list命令来列出当前存在的Docker镜像。

$ sudo docker images
List Docker Images
List Docker Images
列出Docker映像

删除特定的Docker映像(Remove Specific Docker Image)

The first example to remove Docker image is removing single image. We need to specify the image with its name or image id. We will use rmi command which is shortcut of remove image. In this example we will remove the image named ubuntu .

删除Docker映像的第一个示例是删除单个映像。 我们需要使用名称或图像ID指定图像。 我们将使用rmi命令,该命令是删除图像的快捷方式。 在此示例中,我们将删除名为ubuntu的图像。

$ sudo docker rmi ubuntu
Remove Specific Docker Image
Remove Specific Docker Image
删除特定的Docker映像

As we can see from output all layers related with ubuntu image is deleted. In the following example we will provide the image id.

从输出中可以看到,与ubuntu图像相关的所有图层均被删除。 在以下示例中,我们将提供图像ID。

$ sudo docker rmi 3bee3060bfc8
Remove Specific Docker Image
Remove Specific Docker Image
删除特定的Docker映像

列出悬空的Docker映像(List Dangling Docker Images)

As we know docker images consist of different layers. These layers are used by multiple or single images. Sometimes layers can be unrelated with any image. We can list these unused and unrelated docker image layers with -f and dangling=true options.

众所周知,docker映像由不同的层组成。 这些层由多个或单个图像使用。 有时,图层可能与任何图像都不相关。 我们可以使用-fdangling=true选项列出这些未使用且不相关的docker图像层。

$ docker images -f dangling=true

删除悬空的Docker映像 (Remove Dangling Docker Images)

We can remove dangling images by one by one typing the docker image id  but this is not a feasible solution. We can list the dangling docker images id’s with -q parameter .

我们可以通过键入docker image id来删除悬空的映像,但这不是一个可行的解决方案。 我们可以使用-q参数列出悬空的docker映像ID。

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

列出具有指定名称和正则表达式的Docker映像 (List Docker Images With Specified Name and Regex)

In enterprise environments there will be a lot of images we need to cope. We can use pattern search or regex with grep tool to filter and list specific named images. In this example we will list images those contains buntu in their names.

在企业环境中,我们需要处理很多图像。 我们可以使用模式搜索或带有grep工具的正则表达式来过滤和列出特定的命名图像。 在此示例中,我们将列出名称中包含buntu图像。

$ sudo docker images | grep "buntu"
List Docker Images With Specified Name and Regex
List Docker Images With Specified Name and Regex
列出具有指定名称和正则表达式的Docker映像

删除具有指定名称和正则表达式的Docker映像(Remove Docker Images With Specified Name and Regex)

We can use rmi to remove docker images those have specified names or patterns. In this example we will remove images those names have buntu .

我们可以使用rmi删除具有指定名称或模式的docker映像。 在此示例中,我们将删除名称为buntu图像。

$ docker images | grep "buntu" | awk '{print $1}' | xargs docker rmi

列出所有Docker映像 (List All Docker Images)

We can use -a option to list all docker images.

我们可以使用-a选项列出所有docker镜像。

$ docker images -a
List All Docker Images
List All Docker Images
列出所有Docker映像

删除所有Docker映像(Remove All Docker Images)

We can also remove all docker images just using similar technique like previous examples. We will provide the image id’s to the rmi command.

我们还可以使用与先前示例类似的技术删除所有docker映像。 我们将为rmi命令提供图像ID。

$ docker rmi $(docker images -a -q)
LEARN MORE  Linux rm Command Tutorial With Examples
了解更多Linux rm命令教程及示例

翻译自: https://www.poftut.com/how-to-remove-docker-images/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值