A Bash script that keeps Docker Compose projects up to date by pulling fresh images and restarting only the projects where something actually changed.
- Scans every subdirectory of
/volume2/docker/for a Compose file - Skips projects with no running containers
- Pulls the latest images for each running project
- Restarts a project only if at least one image was updated — no unnecessary downtime
- Prints a colour-coded summary of what was updated, skipped, and failed
- Bash 4+
- Docker with the Compose plugin (
docker compose) or standalonedocker-compose sudoaccess for Docker commands
The scan root is hardcoded at the top of the script:
COMPOSE_ROOT="/volume2/docker"Change this to match your setup before running.
Make the script executable once:
chmod +x docker-update.shRun manually:
./docker-update.shRun every night at 03:00:
0 3 * * * /path/to/docker-update.sh >> /var/log/docker-update.log 2>&1Colour output is suppressed automatically when running non-interactively.
- Detects whether to use
docker compose(plugin) ordocker-compose(standalone) - Loops over each subdirectory in
COMPOSE_ROOT - Looks for a Compose file (
docker-compose.yml,docker-compose.yaml,compose.yml,compose.yaml) - Counts running containers — skips the project if none are running
- Runs
compose pulland inspects the output for update markers (Pull complete,Downloaded newer image,Pulled, etc.) - If an update is found: runs
compose downthencompose up -d - Prints a summary and exits with code
1if any project failed
MIT