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?
In addition to Sunny's answer:
In order to delete all images on a Windows machine (with Docker for Windows) in a PowerShell window, do:
In order to delete all containers on a Windows machine (with Docker for Windows) in a PowerShell window, do:
Remove all the containers
Force remove all the Docker images
The image could be currently used by a running container, so you first have to stop and remove the container(s).
Then you could try deleting the image:
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:
Simply you can aadd
--force
at the end of the command. Like:To make it more intelligent you can add as:
Here in
docker ps
$1 is the first column, i.e. the Docker container ID.And
docker images
$3 is the third column, i.e. the Docker image ID.To delete some Docker image you must execute the following command:
So, to delete all Docker images you can execute the following command:
Now, if you want delete all Docker images (including images that are in use), you can add the flag
-f
, for example:If you want to automatically/periodically clean up exited containers and remove images and volumes that aren't in use by a running container you can download the Docker image
meltwater/docker-cleanup
.That way you don't need to go clean it up by hand.
Just run:
It will run every 30 minutes (or however long you set it using DELAY_TIME=1800 option) and clean up exited containers and images.
More details: https://github.com/meltwater/docker-cleanup/blob/master/README.md