Cleaning Docker images

#!/bin/bash
 
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -a -q)

Update. You can also remove data that are no longer used using following command

docker system prune