docker system prune will do the work. It will remove any unused images though. but I am sure, all worthy images should have been pushed to the registry so it should be okay to prune it, depending on your environment though.
If you are running Docker For Windows, the following will work:
echo off&for /f “delims=” %A in ('docker images -f “dangling=true” -q ') do docker rmi %A & echo on
To remove all images which aren’t associated with a running container:
docker image prune -a
The -a parameter is the crucial bit here.
If you want to force the action to occur without a confirmation prompt, you may add the -f parameter, like so:
docker image prune -af
Note: -af is the same as specifying -a and -f separately
If you are like me and keep trying out interactive terminal sessions on images all the time, you will see a lot of : images in the list. They are all linked to stopped containers that you used earlier. Cleanup containers and then cleanup images
docker container prune docker image prune
This worked for me;
Shows all images, copy the ‘Image ID’ of the one you want to delete
sudo docker images
Command to delete, paste image id, without <> and hit enter
sudo docker rmi -f <$imageID>
##Visit your friends at;
On windows, create a new batch file and add the following command,
FOR /f “tokens=*” %%i IN (‘docker images -f “dangling=true” -q’) DO docker rmi %%i -f
This works on my end. Removing all or unused images.
Docker rmi $(docker images -a -q)
docker rmi (docker images -f “dangling=true” -q )