I wrote this four years ago, so instead use this command:
$ docker rmi $(docker images -q -f dangling=true)
the best thing to control and clean up unused containers which still running are to label them on docker run and use few command lines through crontab:
1'st one to kill docker containers creates x time ago and with labe x:
docker ps -a --filter "label=<label_name>" | grep 'x period crated ago' | awk '{ print $1 }' | xargs -I {} docker rm {} -f
2'nd one clean up all unused images which also have tag "none":
docker rmi $(docker images --filter "dangling=true" -q --no-trunc) 2>/dev/null
Then your environment should be always clean :) Cheers....
docker ps -a -q | % { docker rm $_ }
docker images -q | % { docker rmi $_ }
thank you so much
For Windows, what's more:
Stop and remove by image name =>
FOR /f "tokens=*" %i IN ('docker ps -a --filter "ancestor=ImageNameHere" -q') DO docker stop %i && docker rm %i
...
(don't forget to change
%i
to%%i
in batch file)