Skip to content

Instantly share code, notes, and snippets.

@alexjyong
Created February 25, 2025 16:39
Show Gist options
  • Save alexjyong/697d9a6ce5ffff91fdb78a807e4fa73b to your computer and use it in GitHub Desktop.
Save alexjyong/697d9a6ce5ffff91fdb78a807e4fa73b to your computer and use it in GitHub Desktop.
clean-up-docker.sh
#!/bin/bash
echo "This will clean up all Docker resources on your instance."
echo "This is useful if you need to start fresh."
echo "This is also assuming you are running on a codespace instance. This hasn't been tested outside of that."
echo "This is irreversible. Are you sure you want to continue? (Y/N)"
read -r response
if [[ "$response" == "Y" || "$response" == "y" ]]; then
echo "Cleaning up all Docker resources..."
docker system prune -af --volumes && \
docker container prune -f && \
docker volume prune -f && \
docker network prune -f && \
docker image prune -af && \
docker builder prune -af && \
docker rm -f $(docker ps -aq) 2>/dev/null && \
docker rmi -f $(docker images -aq) 2>/dev/null && \
docker volume rm $(docker volume ls -q) 2>/dev/null && \
docker network rm $(docker network ls -q) 2>/dev/null
echo "All Docker resources have been cleaned up."
else
echo "Operation cancelled."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment