Skip to content

Instantly share code, notes, and snippets.

@labboy0276
Last active October 5, 2023 15:40
Show Gist options
  • Save labboy0276/4406db072f9ed3bf3641f57c1d902027 to your computer and use it in GitHub Desktop.
Save labboy0276/4406db072f9ed3bf3641f57c1d902027 to your computer and use it in GitHub Desktop.
Purge all Docker Containers & Lando Cache
#!/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
@generalredneck
Copy link

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!

@labboy0276
Copy link
Author

Does that also get the unused images? other than that it is similar-ish.

@generalredneck
Copy link

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.

@labboy0276
Copy link
Author

fancy

@gitressa
Copy link

gitressa commented Mar 9, 2022

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