Git Product home page Git Product logo

docker-laravel's Introduction

Docker Laravel (LEMP stack with PHP7, ELK, REDIS)

Build Status

The idea of the project is to provide a pre-configured docker platform for Laravel and Lumen apps to get them up and running fast.

Credit: this is a kind of fork from maxpou/docker-symfony. Thanks to him :-) I have made the number of changes to work with Laravel or Lumen apps and modified platform level commands (artisan, composer, mysql) quite easy to access.

Container Architecture

Installation

I assume you have docker-compose installed and either docker-engine running locally (Linux) or have docker-machine (installed via docker-toolbox on OSX, Windows) configured on the computer you use.

  1. Retrieve git project

    $ git clone [email protected]:purinda/docker-laravel.git
  2. Change directory to the docker-laravel (cd docker-laravel)

  3. Symlink your Laravel/Lumen project into app folder (ln -s <absolute-path-of-laravel-project> app)

  4. Build and start containers in detached mode.

    $ docker-compose up -d
  5. Update your host file (add app.dev)

    # get containers IP address and update host (replace IP according to your configuration )
    $ docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -f name=nginx -q)
    $ sudo echo "10.211.55.7 app.dev" >> /etc/hosts

    If you use docker-machine (mainly OSX or Windows) then run the following to get IP address of the vm.

    $ docker-machine ip <machine-name>
    $ echo "10.211.55.7 app.dev" | sudo tee -a /etc/hosts
  6. Prepare Laravel/Lumen app

    1. Update app/.env (adapt hosts according to previous results)

      # Docker database configuration
      DB_CONNECTION=mysql
      DB_DATABASE=laravel
      DB_DATABASE_TEST=laravel_test
      DB_HOST=app.dev
      DB_PORT=3306
      DB_USERNAME=laravel
      DB_PASSWORD=laravel
      
      # Docker SMTP MailCatcher configuration
      MAIL_DRIVER=smtp
      MAIL_HOST=app.dev
      MAIL_PORT=25
      MAIL_FROM_ADDRESS=docker@local
      MAIL_FROM_NAME="Docker"
    2. Composer install

      $ docker-compose exec php composer install
  7. Enjoy :-)

How to use

How it works?

Have a look at the docker-compose.yml file, here are the docker-compose built images:

  • application: This is the Laravel or Lumen application code container,
  • db: This is the MySQL database container,
  • php: This is the PHP-FPM container in which the application volume is mounted,
  • nginx: This is the Nginx webserver container in which application volume is mounted too,
  • elk: This is a ELK stack container which uses Logstash to collect logs, send them into Elasticsearch and visualize them with Kibana,
  • redis: This is a redis database container.

This results in the following running containers:

$ docker-compose ps
           Name                          Command               State              Ports
--------------------------------------------------------------------------------------------------
dockerlaravel_application_1   /bin/bash                        Up
dockerlaravel_db_1            docker-entrypoint.sh mysqld      Up      0.0.0.0:3306->3306/tcp
dockerlaravel_elk_1           /usr/bin/supervisord -n -c ...   Up      0.0.0.0:81->80/tcp
dockerlaravel_nginx_1         nginx                            Up      443/tcp, 0.0.0.0:80->80/tcp
dockerlaravel_php_1           php-fpm                          Up      9000/tcp
dockerlaravel_redis_1         docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp   

Useful commands

# Composer (e.g. composer update)
$ docker-compose exec php composer update

# Laravel Artisan commands (make sure `artisan` script in the app has executable permissions bit set)
$ docker-compose exec php ./artisan

# bash commands
$ docker-compose exec php /bin/bash

# MySQL commands
$ docker-compose exec db mysql -uroot -p"toor" laravel

# Redis commands
$ docker-compose exec redis redis-cli

# Cache/logs folder permissions (use open permissions for development only)
$ chmod -R 777 app/storage/cache app/storage/logs

Running PHPUnit

In order to run the application test suite, it is required to run phpunit which runs against the test database of the application layer.

The script setup-phpunit.sh sets up the test database in the db container and grants required permission for the application test suite.

Script needs docker-machine environment variables (docker-machine env <machine-name>) to be set if you are running containers on docker-machine. Run the script on docker-laravel project directory as below. The script will copy itself into the db container and set up the required configuration.

./setup-phpunit.sh

Lastly, run the unit test suite

docker-compose exec php php vendor/bin/phpunit

docker-laravel's People

Contributors

purinda avatar maxpou avatar developerdino avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.