when building a lot of containers docker can use up a lot of memory with intermediate and dangling containers

docker images -f dangling=true
docker rmi $(docker images -f dangling=true -q)

to stop running containers

docker stop `docker ps -qa`

to remove running containers

docker rm `docker ps -qa`