Skip to content

Instantly share code, notes, and snippets.

@ajmassi
Last active December 14, 2021 19:30
Show Gist options
  • Save ajmassi/3ae8106d5bae5d8ca49b980aab2a49e3 to your computer and use it in GitHub Desktop.
Save ajmassi/3ae8106d5bae5d8ca49b980aab2a49e3 to your computer and use it in GitHub Desktop.
Blow away all Docker containers, images, and artifacts at once.
#!/bin/sh
#"Now I am become rm-f, the destroyer of containers."
echo "Killing running containers..."
cont1=$(docker ps -q)
if [ -n "$cont1"]; then docker kill $cont1; fi
echo
echo "Removing containers..."
cont2=$(docker ps -a -q)
if [ -n "$cont2"]; then docker rm -fv $cont2; fi
echo
echo "Removing images..."
imgs=$(docker images -q)
if [ -n "$imgs"]; then docker rmi -f $imgs; fi
echo
echo "Removing volumes..."
vols=$(docker volume ls -q)
if [ -n "$vols"]; then docker volume rm -f $vols; fi
echo
echo "Removing networks..."
nets=$(docker network ls -q)
if [ -n "$nets"]; then docker network rm $nets 2>/dev/null; fi
echo
echo "Nuke complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment