I\'ve the following images:
alex@alexvps:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
&
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.
Simply you can aadd --force
at the end of the command. Like:
sudo docker rmi <docker_image_id> --force
To make it more intelligent you can add as:
sudo docker stop $(docker ps | grep <your_container_name> | awk '{print $1}')
sudo docker rm $(docker ps | grep <your_container_name> | awk '{print $1}')
sudo docker rmi $(docker images | grep <your_image_name> | awk '{print $3}') --force
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.
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
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.
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`
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:
docker images -q | %{docker rmi -f $_}
In order to delete all containers on a Windows machine (with Docker for Windows) in a PowerShell window, do:
docker ps -a -q | %{docker rm -f $_}