There comes a time, when you just want to purge all the docker things from a machine. Over time, you can accumulate a bunch of garbage, and not even really realize it. While playing around at work and at home, I came up with this little script I use pretty often to clear out my working Docker environment on a system.
#!/bin/sh containers=$(docker ps -a -q) if [ ! -z "$containers" -a "$containers" != " " ]; then echo Stopping $containers docker stop $containers docker rm $containers else echo No containers running fi images=$(docker images -a -q) if [ ! -z "$images" -a "$images" != " " ]; then echo Removing Images $images docker rmi $images else echo No images installed fi docker volume prune -f docker network prune -f
This can be used on Linux, Bash for Windows, and even CGWyn. Basically, stop all containers, remove them, remove all images, prune all volumes, and prune all networks.
If you have any improvements to this, let me know down below in the comments!