how to physically remove untagged docker images

2019-03-12 10:20发布

when I run a command such as sudo docker rmi me/myimage I get the responce ...image untagged, but, when I rerun sudo docker images I can see that this "untagged" image is still there, and, if I run df -h I can see that the actual files still exist and occupy the file system space. What command or procedure can I use to physically remove the unneeded images?

标签: docker
6条回答
Juvenile、少年°
2楼-- · 2019-03-12 10:50

you can delete single images by their image id...

docker images
docker rmi <image-id>
查看更多
别忘想泡老子
3楼-- · 2019-03-12 10:51

First you need to remove exited containers, then remove dangling images.

docker rm $(docker ps -q -f status=exited)
docker rmi $(docker images -q -f dangling=true)

After all, I created the below script as ~/bin/dclean and have been using it.

#!/bin/sh

processes=`docker ps -q -f status=exited`
if [ -n "$processes" ]; then
  docker rm $processes
fi

images=`docker images -q -f dangling=true`
if [ -n "$images" ]; then
  docker rmi $images
fi
查看更多
来,给爷笑一个
4楼-- · 2019-03-12 10:53

If John Petrone solution doesn't work, try removing those images referring explicitly the IMAGE ID you see when you run docker images. You can remove all of them with one command

for i insudo docker images | grep \ | awk '{print $3}'; do sudo docker rmi $i; done

PD: I don't know John Petrone answer. It works nicely with Docker 1.4.1

查看更多
一夜七次
5楼-- · 2019-03-12 10:54

You should be able to remove untagged Docker images using the "dangling=true" flag:

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

source:

https://docs.docker.com/engine/reference/commandline/images/

查看更多
爷的心禁止访问
6楼-- · 2019-03-12 11:02

This command will remove all the dangling images and containers from docker.

docker system prune -f
查看更多
太酷不给撩
7楼-- · 2019-03-12 11:05

This commands also work

docker rmi $(docker images | grep "^<none>" | awk '{print $3}')

Delete images with force to forgo stopped containers that might be using image

docker rmi -f $(docker images | grep "^<none>" | awk '{print $3}')
查看更多
登录 后发表回答