Skip to content

Instantly share code, notes, and snippets.

@tjventurini
Created October 1, 2020 16:36
Show Gist options
  • Save tjventurini/ac9721f19320ee11eb271cd05e86c63e to your computer and use it in GitHub Desktop.
Save tjventurini/ac9721f19320ee11eb271cd05e86c63e to your computer and use it in GitHub Desktop.
Helper for docker-composer.
function dc() {
# check if there is a docker-compose.yml or docker-compose.yaml file in the current directory
if [ -f "./docker-compose.yml" ] || [ -f "./docker-compose.yaml" ]; then
print -P "%F{green}./docker-compose.yml%f"
( docker-compose $* )
return 0
fi
# check if there is a docker directory with a docker-compose.yml or docker-compose.yaml in it.
if [ -f "./docker/docker-compose.yml" ] || [ -f "./docker/docker-compose.yaml" ]; then
print -P "%F{green}.docker%f"
( cd ./docker && docker-compose $* )
return 0
fi
# check if there is a laradock folder in the project
if [ -d "./laradock" ]; then
if [[ $(pwd) == "/home/$USER" ]]; then
print -P "%F{green}~/laradock%f";
else
print -P "%F{green}./laradock%f"
fi
( cd ./laradock && docker-compose $* )
return 0
fi
# otherwise use the one from the home directory
if [ -d "/home/$USER/laradock" ]; then
print -P "%F{green}~/laradock%f"
( cd ~/laradock && docker-compose $* )
return 0
fi
# if none of both are available, then exit with an error
print -P "%F{red}Could not find a docker setup in './docker-compose.yml', './docker', './laradock' or '~/laradock' directories.%f"
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment