我有几个悬挂的图像(出现在docker images
中且没有标签的图像)。要清洁它们,通常的命令是:docker image prune -f
。
但是,此命令不会修剪与容器关联的悬挂图像。不管容器是启动还是停止。
我无法运行docker container prune -f
,因为我不想修剪所有已停止的容器。是否有修剪图像和与图像关联的容器的命令基于图像标签]
对于现有容器,您可能不需要先手动删除容器,然后再手动删除图像
但是将来,您可以采用这种方法
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