Skip to content

Instantly share code, notes, and snippets.

@edilsoncichon
Last active January 17, 2019 21:32
Show Gist options
  • Save edilsoncichon/d746c941fbde9fe76cbeea60eb97d4e5 to your computer and use it in GitHub Desktop.
Save edilsoncichon/d746c941fbde9fe76cbeea60eb97d4e5 to your computer and use it in GitHub Desktop.
Useful/Helpers Commands for working with docker and docker-compose on Laravel.

Simple Environment for Laravel with Docker

Simply copy these two files to the root of your project.

And in the terminal type: $ ./bin up

This should already serve a simple Laravel application in [https://localhost] (https://localhost)

See the "bin" file carefully for the commands that can be executed, and you can add yours easily.

For more information, I recommend the Ambientum repository.

#!/bin/bash
######################################################
# Useful Commands #
######################################################
SERVICE_NAME=app #Replace for your service name.
# Serve your application with zero-configuration (dont need th docker-compose)
# Usage: $ ./bin serve 8080
if [[ $1 = "serve" ]]
then
docker run -p $2:8000 -it --rm -v $(pwd):/var/www/app ambientum/php:7.2 php artisan serve --host=0.0.0.0; exit;
fi
if [[ $1 = "artisan" ]]
then
docker-compose exec ${SERVICE_NAME} php $@; exit;
fi
if [[ $1 = "composer" ]]
then
docker-compose exec ${SERVICE_NAME} $@; exit;
fi
if [[ $1 = "phpunit" ]]
then
docker-compose exec ${SERVICE_NAME} vendor/bin/$@; exit;
fi
if [[ $1 = "up" ]]
then
docker-compose $@; exit;
fi
if [[ $1 = "down" ]]
then
docker-compose $@; exit;
fi
# Run anything in container.
docker-compose exec ${SERVICE_NAME} $@
# See you more examples in: https://github.com/codecasts/ambientum
# v2 syntax
version: '2'
services:
app:
image: ambientum/php:7.2-nginx
container_name: NAME_YOU_APP-app
volumes:
- .:/var/www/app
ports:
- "80:8080"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment