Skip to content

Instantly share code, notes, and snippets.

@rcdevgames
Forked from dantheman213/docker_clean.sh
Created October 6, 2023 09:01
Show Gist options
  • Save rcdevgames/b1177feb10914e0cba0bd732a0d58adc to your computer and use it in GitHub Desktop.
Save rcdevgames/b1177feb10914e0cba0bd732a0d58adc 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!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment