Skip to content

Instantly share code, notes, and snippets.

@fideloper
Created November 24, 2016 02:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fideloper/5f786553225fa1b5b28c6bd76a77f301 to your computer and use it in GitHub Desktop.
Save fideloper/5f786553225fa1b5b28c6bd76a77f301 to your computer and use it in GitHub Desktop.
Helper for Laravel + Docker dev workflow
#!/usr/bin/env bash
# Set environment variables for dev
export APP_ENV=local
export APP_PORT=80
export DB_PORT=3306
export DB_ROOT_PASS=secret
export DB_NAME=homestead
export DB_USER=homestead
export DB_PASS=secret
# If we pass any arguments...
if [ $# -gt 0 ];then
# Get name of current network and docker-compose built image
NETWORK=$(docker network ls | grep sdnet | awk '{print $2}')
IMAGE=$(docker images | grep _app | awk '{print $1}')
# If "art" is used, pass-thru to "artisan"
# inside a new container
if [ "$1" == "art" ]; then
shift 1
docker run --rm -it \
-v $(pwd):/opt \
-w /opt \
--network=$NETWORK \
$IMAGE \
php artisan "$@"
# If "test" is used, run unit tests,
# pass-thru any extra arguments to php-unit
elif [ "$1" == "test" ]; then
shift 1
docker run --rm -it \
-v $(pwd):/opt \
-w /opt \
--network=$NETWORK \
$IMAGE \
./vendor/bin/phpunit
# Else, pass-thru args to docker-compose
else
docker-compose "$@"
fi
fi
@fideloper
Copy link
Author

fideloper commented Nov 24, 2016

Note that this assumes a docker-compose.yml file is present which expects / uses the defined environment variables found in this script.

Notes:

  • I'm using a Docker network called sdnet
  • My main container with php is referenced as app within the docker-compose.yml file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment