add update docker script

This commit is contained in:
Noah vdv
2025-09-20 12:31:48 +02:00
parent fa45faab86
commit da04f340f1
2 changed files with 77 additions and 0 deletions

44
update-docker/README.md Normal file
View File

@@ -0,0 +1,44 @@
# 🛠️ Maintenance Script for Docker Containers
Automates updating your Docker containers on Debian-based systems by pulling the latest images, restarting services, and cleaning up unused resources.
---
## 🚀 Installation, Setup & Running
Download the maintenance script to your Docker project directory:
```bash
# cd into the docker folder
wget -qO update-docker.sh https://gitea.featherer.xyz/nono/update-docker/raw/branch/main/update-docker.sh
source update-docker.sh
```
Or, when run locally (replace the ip address to your own)
```bash
# cd into the docker folder
wget -qO update-docker.sh http://10.1.0.102:3000/nono/update-docker/raw/branch/main/update-docker.sh
source update-docker.sh
```
---
## 🔄 What It Does
1. **Updates system packages**
Runs `apt update` and `apt upgrade -y` to ensure your host is up to date.
2. **Refreshes Docker services**
Executes `docker-compose pull`, `docker-compose down`, and `docker-compose up -d` to fetch new images and restart containers.
3. **Cleans up unused resources**
Calls `docker system prune -a -f` to remove dangling images, stopped containers, and unused networks.
4. **Verifies running containers**
Lists active containers with `docker ps` so you can confirm everything is up and running.
---
## 📝 Prerequisites
- **Debian-based OS** (e.g., Debian, Ubuntu)
- **Docker** & **Docker Compose** installed
- A user with **sudo** privileges or in the **docker** group

View File

@@ -0,0 +1,33 @@
#!/bin/bash
echo "Starting system update and Docker maintenance..."
# Update and upgrade APT packages
echo "Running apt update & upgrade..."
apt update
apt upgrade -y
# Pull latest images, stop containers, and recreate in detached mode
echo "Pulling latest Docker images..."
docker compose pull
echo "Stopping and removing existing containers..."
docker compose down
echo "Starting containers in detached mode..."
docker compose up -d
# Prune unused Docker objects
echo "Pruning unused Docker objects..."
docker system prune -a -f
# Show running containers
echo "Current running Docker containers:"
docker ps
echo "Maintenance complete."
echo "Removing the file"
rm -f ./update-docker.sh
echo "Done!"