mydocker/upgrade-container-by-name.sh

39 lines
782 B
Bash
Executable File

#!/bin/bash
MYDOCKER_PATH="/home/seba/mydocker"
SERVICE="$1"
PRUNE_FLAG="$2"
PRUNE=0
if [[ "$PWD" != "$MYDOCKER_PATH" ]]; then
echo "Are you in ${MYDOCKER_PATH}?"
exit 1
fi
if [[ -z "$SERVICE" ]]; then
echo "Argument with service name not provided"
exit 1
fi
if [[ "$PRUNE_FLAG" == "prune" ]]; then
echo "Pruning existing images"
PRUNE=1
fi
docker compose ps "$SERVICE" >/dev/null || exit 1
echo "Pulling image for $SERVICE..."
docker compose pull "$SERVICE" || exit 1
echo "Stopping $SERVICE..."
docker compose stop "$SERVICE" || exit 1
if [[ "$PRUNE" -eq 1 ]]; then
echo "Pruning system images and cache..."
docker system prune -af || exit 1
fi
echo "Starting $SERVICE..."
docker compose up --detach --force-recreate --no-deps "$SERVICE"