How can I delete Docker's images?

2019-01-07 01:39发布

I've the following images:

alex@alexvps:~$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              70c0e19168cf        5 days ago          1.069 GB
<none>              <none>              c2ce80b62174        8 days ago          399.2 MB
<none>              <none>              60afe4036d97        8 days ago          325.1 MB

and when I try to remove one of them I get:

alex@alexvps:~$ sudo docker rmi 60afe4036d97
Error: Conflict, 60afe4036d97 wasn't deleted
2014/01/28 00:54:00 Error: failed to remove one or more images

How can I remove them? Why is there such conflict?

标签: docker
16条回答
别忘想泡老子
2楼-- · 2019-01-07 02:22

In order to delete all images, use the given command

docker rmi $(docker images -q)

In order to delete all containers, use the given command

docker rm $(docker ps -a -q)

Warning: This will destroy all your images and containers. It will not be possible to restore them!

This solution is provided by Techoverflow.net.

查看更多
Fickle 薄情
3楼-- · 2019-01-07 02:23

I found the answer in this command:

docker images --no-trunc | grep none | awk '{print $3}' | xargs docker rmi

I had your problem when I deleted some images that were being used, and I didn't realise (using docker ps -a).

查看更多
来,给爷笑一个
4楼-- · 2019-01-07 02:23

The most compact version of a command to remove all untagged images is:

docker rmi $(docker images | grep "^<none>" | awk '{print $"3"}')
查看更多
不美不萌又怎样
5楼-- · 2019-01-07 02:24

Possible reason: The reason can be that this image is currently used by a running container. In such case, you can list running containers, stop the relevant container and then remove the image:

docker ps
docker stop <containerid>
docker rm <containerid>
docker rmi <imageid>

If you cannnot find container by docker ps, you can use this to list all already exited containers and remove them.

docker ps -a | grep 60afe4036d97
docker rm <containerid>

Note: Be careful of deleting all exited containers at once in case you use Volume-Only containers. These stay in Exit state, but contains useful data.

查看更多
登录 后发表回答