Created
March 16, 2020 09:51
-
-
Save QNimbus/6067fdc65e96b6255e68e87c927c7cc7 to your computer and use it in GitHub Desktop.
Shell script to run docker-compose in all subfolders
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
#!/usr/bin/env bash | |
## | |
## Title: docker-compose-all.sh | |
## Description: Shell script to run docker-compose in all subfolders | |
## Author: B. van wetten | |
## Created date: 16-03-2020 | |
## Updated date: 16-03-2020 | |
## Version: 0.1.0 | |
## GitHub Gist: https://gist.github.com/6067fdc65e96b6255e68e87c927c7cc7 | |
## | |
## Usage: docker-compose-all.sh [docker-compose parameters] | |
# Shell utilities | |
declare -x SH=$(which sh); [[ $? != 0 ]] && echo "Command 'sh' not found" >&2 && exit 1 | |
declare -x FIND=$(which find); [[ $? != 0 ]] && echo "Command 'find' not found" >&2 && exit 1 | |
declare -x DOCKER=$(which docker); [[ $? != 0 ]] && echo "Command 'docker' not found" >&2 && exit 1 | |
function docker-compose() { | |
${DOCKER} run --rm -v "$PWD:$PWD" -v /var/run/docker.sock:/var/run/docker.sock:ro --workdir="$PWD" docker/compose:latest "$@" | |
} | |
declare -x -f docker-compose | |
function mexec() | |
{ | |
export PARAMS="${@}" | |
${FIND} . -type d -maxdepth 1 -mindepth 1 -print0 | xargs -0 -I{} ${SH} -c 'cd "{}" && docker-compose ${PARAMS}' | |
} | |
mexec ${@} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment