How can I delete Docker's images?

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.


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.


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`

Tags:

Docker