Skip to content

Instantly share code, notes, and snippets.

@tomwojcik
Last active July 21, 2021 15:23
Show Gist options
  • Save tomwojcik/549ddf72117127e54b8317f690954072 to your computer and use it in GitHub Desktop.
Save tomwojcik/549ddf72117127e54b8317f690954072 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# run from terminal with
# bash <(curl -Ls gist.githubusercontent.com/tomwojcik/549ddf72117127e54b8317f690954072/raw/1e609d631bffd12aa4e4e526e789821ae6650167/nuke_docker_env.sh)
echo "Stopping all running containers"
docker stop $(docker ps -aq) > /dev/null
echo "Removing all containers"
docker rm $(docker ps -aq) > /dev/null
echo "Removing all images. It might take a few minutes..."
docker rmi $(docker images --filter "dangling=true" -q --no-trunc) > /dev/null
docker rmi $(docker images -q) -f > /dev/null
echo "Removing unused non-default volumes"
yes | docker volume prune > /dev/null
echo "Removing unused non-default networks"
yes | docker network prune > /dev/null
echo "Docker env purged. Happy hacking!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment