最佳做法是根据图像标签修剪具有关联容器的悬挂图像?

问题描述 投票:0回答:1

我有几个悬挂的图像(出现在docker images中且没有标签的图像)。要清洁它们,通常的命令是:docker image prune -f

但是,此命令不会修剪与容器关联的悬挂图像。不管容器是启动还是停止。

我无法运行docker container prune -f,因为我不想修剪所有已停止的容器。是否有修剪图像和与图像关联的容器的命令基于图像标签]

docker docker-image
1个回答
-1
投票

对于现有容器,您可能不需要先手动删除容器,然后再手动删除图像

但是将来,您可以采用这种方法

Before starting container you need to decide first that on whenever container get stopped whether you need container or not
if not then append --rm command on docker run,--rm will delete the container whenever it gets stopped

使用--rm启动nginx的示例命令

sudo docker run --name myngixtest -d --rm nginx:latest

© www.soinside.com 2019 - 2024. All rights reserved.