My favorite way of removing all stopped docker containers is:
docker ps -q |xargs docker rm
it will list all images (docker ps), but only show the id’s. And then run a docker rm command for each one of them.
Similarly for removing all unused docker images
docker images -q |xargs docker rmi
Will list all docker images and then docker rmi them.