-
-
Save acrossoffwest/6ac8071d1ead5589f32d3ed605a2712c to your computer and use it in GitHub Desktop.
Laravel Docker Compose Bash - tools for fast enter in bash of specific docker container
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 | |
POSITIONAL=() | |
while [[ $# -gt 0 ]] | |
do | |
key="$1" | |
case $key in | |
-f|--force) | |
FORCE="TRUE" | |
shift # past argument | |
shift # past value | |
;; | |
*) # unknown option | |
POSITIONAL+=("$1") # save it in an array for later | |
shift # past argument | |
;; | |
esac | |
done | |
set -- "${POSITIONAL[@]}" # restore positional parameters | |
COLUMNS=25 | |
PS3='Please enter your container: ' | |
GREP='' | |
options=($(docker ps --format '{{.Names}}')) | |
if [ -z "$FORCE" ]; then | |
if [ -f "./docker/.env" ]; then | |
source ./docker/.env | |
if [ -n "$COMPOSE_PROJECT_NAME" ]; then | |
GREP="$(echo ${COMPOSE_PROJECT_NAME})" | |
options=( $( for i in ${options[@]} ; do echo $i ; done | grep $GREP ) ) | |
fi | |
fi | |
fi | |
select answer in "${options[@]}"; do | |
for item in "${options[@]}"; do | |
if [[ $item == $answer ]]; then | |
break 2 | |
fi | |
done | |
done | |
docker exec -ti $answer bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment