How to wipe your local docker environment

When playing with docker on your local workstation it’s sometimes necessary to wipe the entire environment clean, but there is no single docker command which would do just that.

When looking for a solution I found this useful docker script that removes everything:

#!/bin/bash

echo Killing all containers
for i in $( docker ps -q ) ; do
 docker kill $i
done

echo Removing all containers
for i in $( docker ps -aq ) ; do
 docker rm $i
done

echo Removing all images
for i in $( docker images -q ) ; do
 docker rmi -f $i
done

echo Removing all networks
for i in $( docker network ls -q ) ; do
 docker network rm $i
done

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.