This guide will explain, how to install and configure docker on a linux distribution.
Make sure you follow the official Docker install guide.
To manage Docker as non-root visit the offical docs.
Can be passed in some other place as path/to/.sh dir-to-search excluded-dir-1 excluded-dir-2 ...
#!/bin/bash
# Function to check if directory should be excluded
should_exclude() {
local dir_name="$1"
local excluded_dirs=( "${@:2}" )
for excluded_dir in "${excluded_dirs[@]}"; do
if [[ "$dir_name" == "$excluded_dir" ]]; then
return 0
fi
done
return 1
}
# Recursive function to search for compose.yml files and execute commands
search_and_execute() {
local search_dir="$1"
local excluded_dirs=( "${@:2}" )
find "$search_dir" -mindepth 1 -maxdepth 1 -type d | while IFS= read -r dir; do
# Get the directory name
dir_name=$(basename "$dir")
# Check if the directory should be excluded
should_exclude "$dir_name" "${excluded_dirs[@]}" && continue
# Check if compose.yml file exists in the directory
if [ -f "$dir/compose.yml" ]; then
echo "Executing command in $dir"
(cd "$dir" && docker compose pull && docker compose up -d)
fi
# Recursively search subdirectories
search_and_execute "$dir" "${excluded_dirs[@]}"
done
}
# Start the search from the specified directory
search_and_execute "$1" "${@:2}"