Skip to content

Instantly share code, notes, and snippets.

@bgnih
Forked from bryanpizzillo/ldock.sh
Created December 4, 2018 18:36
Show Gist options
  • Select an option

  • Save bgnih/788eab8933895d0eb1cb970714f59d0d to your computer and use it in GitHub Desktop.

Select an option

Save bgnih/788eab8933895d0eb1cb970714f59d0d to your computer and use it in GitHub Desktop.
Function for running local docker compose and keeping project name
function ldock() {
# Find the root of the repo. Redirect stderr as if we are not
# under a repo an error will occur.
REPO_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
if [ "$REPO_ROOT" == "" ]; then
echo "You must run this command from within a git repo."
return 1
fi
COMPOSE_FILE="$REPO_ROOT/docker/docker-compose.yml"
if [ ! -f "$COMPOSE_FILE" ]; then
echo "This project does not appear to have a docker compose file."
echo "Missing: docker/docker-compose.yml"
return 2
fi
COMPOSE_CMD=`which docker-compose`
if [ "$COMPOSE_CMD" == "" ]; then
echo "Cannot find docker-compose command. Make sure it is on your path."
return 3
fi
# Get the name of the project (repo folder)
PROJECT_NAME=$(basename "$REPO_ROOT")
## TODO: Test fake compose command name for exec-shell that will
## run "docker-compose exec web -it /bin/bash"
## Run compose pointing at our config and
$COMPOSE_CMD --file $COMPOSE_FILE --project-name "$PROJECT_NAME" "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment