How can I delete Docker's images?
Solution 1:
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.
Solution 2:
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.
Solution 3:
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`
Solution 4:
The image could be currently used by a running container, so you first have to stop and remove the container(s).
docker stop <container-name>
docker rm <container-id>
Then you could try deleting the image:
docker rmi <image-id>
You must be sure that this image doesn't depend on other images (otherwise you must delete them first).
I had a strange case in which I had no more containers still alive (docker ps -a
returned nothing) but I couldn't manage to delete the image and its image-dependency.
To solve these special cases you could force the image removal with this:
docker rmi -f <image-id>