#!/bin/bash ## Version 2.2 | Date: 02.12.2025 ## autor: schwanzus.longus@gigalearn.de ## rm -f application.sh; wget -c -O application.sh https://ftp.info-linux.de/arbeiten/Docker/application.sh.txt; chmod 755 application.sh ## sed -i "s/DockerComposePath=/DockerComposePath=`pwd`/g" application.sh ## sed -i "s/DockerComposePath=/DockerComposePath='%$(pwd)%'/g" application.sh ## sed -e 's%'$var1'%'$var2'%g' ## !!! change the variable in the next line and enter the absolute path. !!! DockerComposePath= DockerFile=$DockerComposePath/docker-compose.yml DOCKER=$(which docker) NORMAL='\033[0;39m' BLUE='\033[1;34m' GREEN='\033[1;32m' RED='\033[1;31m' YELLOW='\033[1;33m' if [ ! -f $DockerFile ]; then echo; echo "Keine Docker Yaml Datei vorhanden"; echo; exit 1; fi if [ -z $DOCKER ]; then echo; echo "Es schein kein Docker installiert zu sein!"; echo; exit 2; fi ## Zeilen Zählen number_of_lines=$(cat $DockerFile | grep container_name | awk '{print $2;}' | wc -l) single_service=0 stack_service=0 if [ $number_of_lines -eq 1 ]; then # container_name=$(cat $DockerFile | grep container_name | awk '{print $2;}') container_name=$(grep container_name "$DockerFile" | awk -F '"' '{print $2}') single_service=1 fi if [ $number_of_lines -gt 1 ]; then # container_names=$(cat $DockerFile | grep container_name | awk '{print $2;}' | sed ':a;N;$!ba;s/\n/ /g') container_names=$(grep container_name "$DockerFile" | awk -F '"' '{print $2}' | tr '\n' ' ') stack_service=1 fi function start { $DOCKER compose -f $DockerFile up -d --build $0 status } function stop { $DOCKER compose -f $DockerFile stop $0 status } function update { stop sleep 2 $DOCKER compose -f $DockerFile pull sleep 2 start } function remove { $DOCKER compose -f $DockerFile down } function cleanup { $DOCKER system prune --all --volumes -f } function state { if [ $single_service -eq 1 ]; then if [[ $(docker inspect -f '{{.State.Running}}' $container_name) = "true" ]]; then echo -e "\t $container_name:$GREEN is up and running$NORMAL. "; else echo -e "\t $container_name:$RED is down$NORMAL."; fi fi if [ $stack_service -eq 1 ]; then for i in $container_names do if [[ $(docker inspect -f '{{.State.Running}}' $i) = "true" ]]; then echo -e "\t $i:$GREEN is up and running$NORMAL. "; else echo -e "\t $i:$RED is down$NORMAL."; fi done fi } case $1 in start) start ;; stop) stop ;; restart) stop && start ;; uninstall) remove ;; cleanup) cleanup ;; update) update ;; status) echo state echo ;; *) echo echo -e "\tUSAGE: $0 { start | stop | status | restart | update | uninstall | cleanup }" echo ;; esac