Last active
January 15, 2024 18:36
-
-
Save YannBirba/7f008b59ee1b2a43a4358e3baf22ed79 to your computer and use it in GitHub Desktop.
Start all docker containers in specific dir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
### | |
# Created date: 17/12/2023 | |
# Created by: Yann Birba | |
# Description: Script to start docker containers | |
### | |
# Variables | |
# Colors | |
red='\033[0;31m' | |
green='\033[0;32m' | |
yellow='\033[0;33m' | |
cyan='\033[0;36m' | |
bold='\033[1m' | |
NC='\033[0m' # No Color | |
# App dir where all docker compose files are | |
apps_dir="/home/yann" | |
# get all apps dir (except nginx-proxy, adguard, portainer and diun) + all dir thats starts with a underscore | |
# shellcheck disable=SC2010 | |
apps=$(ls $apps_dir | grep -v "nginx-proxy\|adguard\|portainer\|diun\uptime-kuma" | grep -v "^_") | |
# Functions | |
function start_app() { | |
echo "Starting $1 ..." | |
if ! cd $apps_dir/"$1" ; then | |
echo -e "${red}${bold}Error: $1 doesn't exist${NC}" | |
return | |
fi | |
# Check if app is already running | |
if docker-compose ps | grep -q "Up"; then | |
echo -e "${yellow}${bold}$1 is already running${NC}" | |
return | |
fi | |
docker-compose up -d | |
if docker-compose ps | grep -q "Up"; then | |
echo -e "${green}${bold}v $1 started !${NC}" | |
else | |
echo -e "${red}${bold}Error: $1 not started${NC}" | |
fi | |
} | |
# Script | |
# First start reverse proxy | |
start_app "nginx-proxy" | |
# Start dns server | |
start_app "adguard" | |
# Start portainer | |
start_app "portainer" | |
# Then start diun | |
start_app "diun" | |
# Start apps | |
for app in $apps; do | |
start_app "$app" | |
done | |
start_app "uptime-kuma" | |
echo "" | |
echo -e "${cyan}${bold}v All apps started !${NC}" | |
echo "" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to paste in /usr/local/bin