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:09

You have to stop/delete all unnecessary containers created on that images first.

Have a look: How to remove old Docker containers.

After that use @marcell solution.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-07 02:12

In Bash:

for i in `sudo docker images|grep \<none\>|awk '{print $3}'`;do sudo docker rmi $i;done

This will remove all images with name "<none>". I found those images redundant.

查看更多
家丑人穷心不美
4楼-- · 2019-01-07 02:16

The reason for the error is that even though the image did not have any tag, there still exists a container created on that image which might be in the exited state. So you need to ensure that you have stopped and deleted all containers created on those images. The following command helps you in removing all containers that are not running:

docker rm `docker ps -aq --no-trunc --filter "status=exited"`

Now this removes all the dangling non-intermediate <none> images:

docker rmi `docker images --filter 'dangling=true' -q --no-trunc`

Note: To stops all running containers:

docker stop `docker ps -q`
查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-07 02:20

Since Docker ver. 1.13.0 (January 2017) there's the system prune command:

$ docker system prune --help

Usage:  docker system prune [OPTIONS]

Remove unused data

Options:
-a, --all     Remove all unused images not just dangling ones
-f, --force   Do not prompt for confirmation
    --help    Print usage
查看更多
孤傲高冷的网名
6楼-- · 2019-01-07 02:20

Use

docker image prune -all

or

docker image prune -a

Remove all dangling images. If -a is specified, it will also remove all images not referenced by any container.

Note: You are prompted for confirmation before the prune removes anything, but you are not shown a list of what will potentially be removed. In addition, docker image ls does not support negative filtering, so it difficult to predict what images will actually be removed.

As stated under Docker's documentation for prune.

查看更多
狗以群分
7楼-- · 2019-01-07 02:21

First, remove all the containers using the following command

sudo docker ps -a -q | xargs -n 1 -I {} sudo docker rm {}

Then, remove the image by its ID using the following command

sudo docker rmi <image-id>
查看更多
登录 后发表回答