Add Docker cleanup script and README

This commit is contained in:
Christopher
2023-11-15 13:27:48 -06:00
parent 01015f5a97
commit 504fb592ae
2 changed files with 70 additions and 0 deletions

9
docker-cleanup/README.md Normal file
View File

@@ -0,0 +1,9 @@
## Why?
This is a handy script to clean up a docker instance.
## How to use?
```bash
bash -c "$(wget -qLO - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/docker-cleanup/run.sh)"
```

61
docker-cleanup/run.sh Normal file
View File

@@ -0,0 +1,61 @@
#!/bin/bash
echo "---------------------"
echo "Big Bear Docker Cleanup Script"
echo "---------------------"
echo "Made by BigBearTechWorld"
echo "---------------------"
echo "Like the script? Consider supporting my work at: https://ko-fi.com/bigbeartechworld"
echo "---------------------"
# Function to delete Docker containers
cleanup_containers() {
echo "Current Docker Containers:"
docker ps -a
read -p "Do you want to remove all stopped containers? (y/n): " answer
if [[ "$answer" == "y" ]]; then
docker container prune -f
echo "Stopped containers removed."
fi
}
# Function to delete Docker images
cleanup_images() {
echo "Current Docker Images:"
docker images
read -p "Do you want to remove unused Docker images? (y/n): " answer
if [[ "$answer" == "y" ]]; then
docker image prune -a -f
echo "Unused images removed."
fi
}
# Function to delete Docker volumes
cleanup_volumes() {
echo "Current Docker Volumes:"
docker volume ls
read -p "Do you want to remove unused Docker volumes? (y/n): " answer
if [[ "$answer" == "y" ]]; then
docker volume prune -f
echo "Unused volumes removed."
fi
}
# Function to delete Docker networks
cleanup_networks() {
echo "Current Docker Networks:"
docker network ls
read -p "Do you want to remove unused Docker networks? (y/n): " answer
if [[ "$answer" == "y" ]]; then
docker network prune -f
echo "Unused networks removed."
fi
}
# Execute cleanup functions
cleanup_containers
cleanup_images
cleanup_volumes
cleanup_networks
echo "Docker cleanup completed."