Last active
October 5, 2023 15:40
-
-
Save labboy0276/4406db072f9ed3bf3641f57c1d902027 to your computer and use it in GitHub Desktop.
Purge all Docker Containers & Lando Cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo 'Stopping Containers' | |
# Stop all containers | |
containers=`docker ps -a -q` | |
if [ -n "$containers" ] ; then | |
docker stop $containers | |
fi | |
echo 'Deleting Containers' | |
# Delete all containers | |
containers=`docker ps -a -q` | |
if [ -n "$containers" ]; then | |
docker rm -f -v $containers | |
fi | |
echo 'Deleting Images' | |
# Delete all images | |
images=`docker images -q -a` | |
if [ -n "$images" ]; then | |
docker rmi -f $images | |
fi | |
echo 'Pruning Network' | |
docker network prune -f | |
echo 'Purging Lando Cache' | |
rm -rf ~/.lando/cache |
Does that also get the unused images? other than that it is similar-ish.
Oh yeah... it deletes all containers, volumes, images, networks... It's the holy grail of nuke everything in docker and start from scratch. Check out the second example on https://docs.docker.com/engine/reference/commandline/system_prune/#examples. it has an explaination.
fancy
Thanks for sharing @generalredneck, that does the job perfectly, and everything gets cleaned up nicely.
I was just about to suggest adding it to the documentation, but when I looked, I see you beat me to it @labboy0276 :)
https://docs.lando.dev/help/purging-containers.html
PS. "behvaior"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick question...
How is this different from just running
lando poweroff && docker system prune -a --volumes && rm -rf ~/.lando/cache
?Not criticizing, just learning what I'm missing. :)
Thanks for helping everyone out!