script_collection/container-update.sh
2024-07-07 21:17:01 +02:00

36 lines
842 B
Bash

#!/usr/bin/env bash
set -e
for compose_file in /opt/docker/**/docker-compose.yml; do
if [[ $(docker compose -f "$compose_file" ps -q) ]]; then
echo "> Updating $compose_file"
docker compose -f "$compose_file" pull
docker compose -f "$compose_file" up -d --remove-orphans
echo ""
else
echo "> Skipping $compose_file as it's not running."
echo ""
fi
done
echo "> Containers have been updated."
confirm=n
echo "
> WARNING! The following confirmation will remove:
> - all stopped containers
> - all networks not used by at least one container
> - all dangling images
> - unused build cache"
read -rp "> Do you want to prune docker? [y/N] " confirm
echo ""
if [[ $confirm == [yY] ]]; then
docker system prune -f -a
echo "> Docker has been pruned."
else
echo "> Nothing has been changed."
fi
exit