To remove all containers,
docker rm -vf $(docker ps -a -q)
-v : delete all associated volumes
-f : force deletion. For example, if any containers are running, you need to -f delete them.
To delete all images,
docker rmi -f $(docker images -a -q)
-a : for all containers, not even working (or images)
-q : remove all details other than the identifier of the containers (or images)
source share