init
This commit is contained in:
commit
b603381c5e
|
|
@ -0,0 +1,49 @@
|
|||
#!/bin/bash
|
||||
|
||||
# --- CONFIGURATION ---
|
||||
# Add the paths to the directories containing your docker-compose.yml files
|
||||
# Example: SERVICES=("/home/user/homeassistant" "/home/user/nginx")
|
||||
SERVICES=(
|
||||
"/root/"
|
||||
)
|
||||
|
||||
# Color codes for better readability
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo "Starting Docker services update..."
|
||||
|
||||
for dir in "${SERVICES[@]}"; do
|
||||
if [ -d "$dir" ] && [ -f "$dir/docker-compose.yml" ]; then
|
||||
echo -e "\nUpdating service in: ${GREEN}$dir${NC}"
|
||||
|
||||
# Move into the directory
|
||||
cd "$dir" || continue
|
||||
|
||||
# 1. Pull the latest images
|
||||
if docker compose pull; then
|
||||
echo "Images pulled successfully."
|
||||
|
||||
# 2. Recreate containers with the new images
|
||||
# --detach: runs in background
|
||||
# --remove-orphans: cleans up old services no longer in the file
|
||||
if docker compose up -d --remove-orphans; then
|
||||
echo -e "${GREEN}Successfully updated!${NC}"
|
||||
else
|
||||
echo -e "${RED}Failed to restart containers.${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}Failed to pull images. Skipping this service.${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "\n${RED}Error:${NC} Directory or docker-compose.yml not found at $dir"
|
||||
fi
|
||||
done
|
||||
|
||||
# 3. Cleanup
|
||||
echo -e "\nCleaning up unused images..."
|
||||
docker image prune -f
|
||||
|
||||
echo -e "\n${GREEN}All updates complete!${NC}"
|
||||
|
||||
Loading…
Reference in New Issue