Over time it’s easy for the number of stopped docker containers to steadily increase. To periodically clean up the stopped containers:
$ docker rm $(docker ps --filter "status=exited" -q)
$ docker rm $(docker ps --filter "status=dead" -q)
To clear up their images, providing your setup is simple then you can remove all images, trusting docker not to remove any that are used by a running container:
$ docker rmi $(docker images -a -q)