Skip to content

Instantly share code, notes, and snippets.

@dantheman213
Last active October 6, 2023 09:01
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dantheman213/d4329c15911b48ff44d4bce5de8a7067 to your computer and use it in GitHub Desktop.
Save dantheman213/d4329c15911b48ff44d4bce5de8a7067 to your computer and use it in GitHub Desktop.
Reset Docker to a clean vanilla state
#!/usr/bin/env bash
# Reset Docker to a clean vanilla state. Will destroy all containers, images, networks, volumes, and cache.
[ $(docker ps | wc -l) -ne 1 ] && echo "Stopping all containers..." && docker stop $(docker ps | sed -n '1d;p' | awk -F" " '{print $1}')
[ $(docker ps -a | wc -l) -ne 1 ] && echo "Deleting all containers..." && docker rm $(docker ps -a | sed -n '1d;p' | awk -F" " '{print $1}')
[ $(docker images | wc -l) -ne 1 ] && echo "Deleting all images..." && docker image rm $(docker images | sed -n '1d;p' | awk -F" " '{print $3}')
echo "Pruning networks, volumes, and cache..." && docker system prune -a -f --volumes
echo "Docker is back to Vanilla... COMPLETE!"
@dantheman213
Copy link
Author

dantheman213 commented Mar 1, 2020

Download and install into your local system:

curl https://gist.githubusercontent.com/dantheman213/d4329c15911b48ff44d4bce5de8a7067/raw/dbf3886a3e4673e97f2ac6243311f2ca8df66f08/docker_clean.sh -o /usr/bin/docker_clean; chmod +x /usr/bin/docker_clean

And use whenever needed:

docker_clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment