如何删除所有Docker容器映像?

Docker is very popular container technology. Docker is supported by Linux distributions and Windows operating systems. While using containers we may need to remove all container images from docker engine. We will look different ways to remove all docker container images in this tutorial.

Docker是非常流行的容器技术。 Linux发行版和Windows操作系统均支持Docker。 使用容器时,我们可能需要从Docker引擎中删除所有容器映像。 在本教程中,我们将寻找不同的方式来删除所有docker容器映像。

列出Docker映像 (List Docker Images)

Before removing images we generally need to list existing images to be sure. This is a safety step to prevent catastrophic actions like checking before dd command. We will use sudo docker images . We use sudo  because we need  root privileges or be in docker user group.

在删除图像之前,我们通常需要列出现有图像以确保确定。 这是安全的步骤,可防止灾难性行为,例如在dd命令之前进行检查。 我们将使用sudo docker images 。 我们使用sudo是因为我们需要root特权或位于docker用户组中。

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

删除所有容器(Delete All Containers)

Containers are instances created from the images. We can delete these instances or container images. We will use docker ps  command to list them and provide their UID to the docker rm  command which will delete given container.

容器是根据映像创建的实例。 我们可以删除这些实例或容器图像。 我们将使用docker ps命令列出它们,并将其UID提供给docker rm命令,该命令将删除给定的容器。

$ sudo docker rm $(sudo docker ps -a -q)
Delete All Containers
Delete All Containers
删除所有容器

As we can see that deleted container UID is printed to the terminal output.

如我们所见,已删除的容器UID将打印到终端输出。

删除所有图像 (Delete All Images)

Images are pure data about the starting point of the containers. We generally download images from docker hub or create them and store for daily usage. If we do not need them we can delete then with docker rmi  command but we should provide images UID with the docker images command like below.

图像是有关容器起点的纯数据。 我们通常从docker hub下载图像或创建图像并存储以供日常使用。 如果我们不需要它们,可以使用docker rmi命令删除它,但是我们应该使用docker images命令提供图像UID,如下所示。

$ sudo docker rmi -f $(sudo docker images -q)
Delete All Images
Delete All Images
删除所有图像

强制删除具有附加卷的所有图像(Delete All Images Forcibly with Attached Volumes)

If there are some issues while deleting docker images and volumes we may need to force them for removal. We will use -f option to for remove all docker images and containers. We will also use -v option for verbosity in conjunction with -f .

如果删除docker映像和卷时遇到一些问题,我们可能需要强制将其删除。 我们将使用-f选项删除所有docker映像和容器。 我们还将-v选项与-f一起用于详细信息。

$ sudo docker rm -vf $(sudo docker ps -a -q)

删除所有未使用的图像和卷 (Delete All Unused Images and Volumes)

Docker engine is an intellygent mechanism where is monitors image and volume usage. Most of the cases there will be unused images and volumes where they take storage. We can use system prune to remove unused images and volumes. We can also put this command into cron to made it automatic.

Docker引擎是一种智能机制,可监视映像和卷使用情况。 大多数情况下,会有未使用的映像和卷存储在其中。 我们可以使用system prune删除未使用的映像和卷。 我们还可以将此命令放入cron以使其自动执行。

$ sudo docker system prune --all

Delete All Unused Images and Volumes
Delete All Unused Images and Volumes
删除所有未使用的图像和卷
LEARN MORE  Linux Crontab Tutorial with Examples To Schedule Jobs
了解更多Linux Crontab教程,并附有计划作业的示例

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值