Skip to content

Instantly share code, notes, and snippets.

@acrossoffwest
Last active July 21, 2021 12:28
Show Gist options
  • Save acrossoffwest/6ac8071d1ead5589f32d3ed605a2712c to your computer and use it in GitHub Desktop.
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
#!/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