Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 \
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 \
# Else, pass-thru args to docker-compose
docker-compose "$@"

This comment has been minimized.

Copy link
Owner 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.


  • 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
You can’t perform that action at this time.