-
-
Save bgnih/788eab8933895d0eb1cb970714f59d0d to your computer and use it in GitHub Desktop.
Function for running local docker compose and keeping project name
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
| 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