├── .gitignore ├── .travis.yml ├── README.md ├── code └── Dockerfile ├── docker-compose.yml ├── docs └── container-architecture.png ├── elk └── logstash │ ├── logstash.conf │ └── patterns │ ├── default.conf │ └── nginx.conf ├── mailcatcher └── Dockerfile ├── nginx ├── Dockerfile ├── laravel.conf └── nginx.conf ├── php7-fpm └── Dockerfile └── setup-phpunit.sh /.gitignore: -------------------------------------------------------------------------------- 1 | /logs 2 | /app 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | env: 4 | DOCKER_COMPOSE_VERSION: 1.29.0 5 | 6 | services: 7 | - docker 8 | 9 | before_install: 10 | - mkdir app 11 | - sudo rm /usr/local/bin/docker-compose 12 | - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose 13 | - chmod +x docker-compose 14 | - sudo mv docker-compose /usr/local/bin 15 | 16 | script: 17 | - docker-compose up -d 18 | - docker-compose ps 19 | 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Laravel (LEMP stack with PHP7, ELK, REDIS) 2 | 3 | [![Build Status](https://travis-ci.com/purinda/docker-laravel.svg?branch=master)](https://travis-ci.com/purinda/docker-laravel) 4 | 5 | **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.** 6 | 7 | *Credit: this is a fork from [maxpou/docker-symfony](https://github.com/maxpou/docker-symfony). Thanks to him :-)* 8 | 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. 9 | 10 | ![Container Architecture](https://raw.githubusercontent.com/purinda/docker-laravel/master/docs/container-architecture.png) 11 | 12 | ## Installation 13 | 14 | I assume you have `docker-compose` installed and either **docker-engine** running locally (Linux) or have **docker-machine** (installed via [docker-toolbox](https://www.docker.com/products/docker-toolbox) on OSX, Windows) 15 | configured on the computer you use. _NOTE: if you use docker-machine (deprecated project so recommend not to) you may need to use the docker-machine IP address instead of `localhost` URLs mentioned below_ 16 | 17 | 1. Retrieve git project 18 | 19 | ```bash 20 | $ git clone git@github.com:purinda/docker-laravel.git 21 | ``` 22 | 23 | 2. Change directory to the `docker-laravel` (`cd docker-laravel`) 24 | 25 | 3. Symlink your Laravel/Lumen project into app folder (`ln -s app`) 26 | 27 | 4. Build and start containers in detached mode. 28 | 29 | ```bash 30 | $ docker-compose up -d 31 | ``` 32 | 33 | 5. Prepare Laravel/Lumen app 34 | 1. Update app/.env (adapt hosts according to previous results) 35 | 36 | ```ini 37 | # Docker database configuration 38 | DB_CONNECTION=mysql 39 | DB_DATABASE=laravel 40 | DB_DATABASE_TEST=laravel_test 41 | DB_HOST=db 42 | DB_PORT=3306 43 | DB_USERNAME=laravel 44 | DB_PASSWORD=laravel 45 | 46 | # Docker SMTP MailCatcher configuration 47 | MAIL_DRIVER=smtp 48 | MAIL_HOST=mailcatcher 49 | MAIL_PORT=25 50 | MAIL_FROM_ADDRESS=docker@local 51 | MAIL_FROM_NAME="Docker" 52 | ``` 53 | 54 | 2. Composer install 55 | 56 | ```yml 57 | $ docker-compose exec php composer install 58 | ``` 59 | 60 | 6. Enjoy 😀 61 | 62 | ## How to use 63 | 64 | * Laravel app: visit [localhost](http://localhost) 65 | * Logs (Kibana): [localhost:81](http://localhost:81) 66 | * Logs (files location): logs/nginx and logs/laravel 67 | * MailCatcher: [localhost:82](http://localhost:82) 68 | - For instructions please refer to https://mailcatcher.me/ 69 | 70 | ## How it works? 71 | 72 | Have a look at the `docker-compose.yml` file, here are the `docker-compose` built images: 73 | 74 | * `application`: This is the Laravel or Lumen application code container, 75 | * `db`: This is the MySQL database container, 76 | * `php`: This is the PHP-FPM container in which the application volume is mounted, 77 | * `nginx`: This is the Nginx webserver container in which application volume is mounted too, 78 | * `elk`: This is a ELK stack container which uses Logstash to collect logs, send them into Elasticsearch and visualize them with Kibana, 79 | * `redis`: This is a redis database container. 80 | 81 | This results in the following running containers: 82 | 83 | ```bash 84 | $ docker-compose ps 85 | Name Command State Ports 86 | -------------------------------------------------------------------------------------------------------------------------------------------------- 87 | docker-laravel_application_1 /bin/sh Up 88 | docker-laravel_db_1 docker-entrypoint.sh mysqld Up 3306/tcp 89 | docker-laravel_elk_1 /usr/bin/supervisord -n -c ... Up 0.0.0.0:81->80/tcp,:::81->80/tcp 90 | docker-laravel_mailcatcher_1 /bin/sh -c mailcatcher -f ... Up 0.0.0.0:25->1025/tcp,:::25->1025/tcp, 0.0.0.0:82->1080/tcp,:::82->1080/tcp 91 | docker-laravel_nginx_1 nginx Up 443/tcp, 0.0.0.0:80->80/tcp,:::80->80/tcp 92 | docker-laravel_php_1 docker-php-entrypoint php-fpm Up 9000/tcp 93 | docker-laravel_redis_1 docker-entrypoint.sh redis ... Up 6379/tcp 94 | ``` 95 | 96 | ## Useful commands 97 | 98 | ```bash 99 | # Composer (e.g. composer update) 100 | $ docker-compose exec php composer update 101 | 102 | # Laravel Artisan commands (make sure `artisan` script in the app has executable permissions bit set) 103 | $ docker-compose exec php ./artisan 104 | 105 | # bash commands 106 | $ docker-compose exec php /bin/bash 107 | 108 | # MySQL commands 109 | $ docker-compose exec db mysql -uroot -p"toor" laravel 110 | 111 | # Redis commands 112 | $ docker-compose exec redis redis-cli 113 | 114 | # Cache/logs folder permissions (use open permissions for development only) 115 | $ chmod -R 777 app/storage/cache app/storage/logs 116 | 117 | ``` 118 | 119 | ## Running PHPUnit 120 | 121 | In order to run the application test suite, it is required to run `phpunit` which runs against the test database of the 122 | application layer. 123 | 124 | The script `setup-phpunit.sh` sets up the test database in the `db` container and grants required permission for the application 125 | test suite. 126 | 127 | Script needs docker-machine environment variables (`docker-machine env `) to be set if you are running 128 | containers on `docker-machine`. Run the script on `docker-laravel` project directory as below. The script will copy itself into 129 | the db container and set up the required configuration. 130 | 131 | ./setup-phpunit.sh 132 | 133 | Lastly, run the unit test suite 134 | 135 | docker-compose exec php php vendor/bin/phpunit 136 | -------------------------------------------------------------------------------- /code/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | 3 | VOLUME /var/www/laravel 4 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | application: 4 | build: code 5 | volumes: 6 | # Symlink or setup Laravel/Lumen on ./app directory. 7 | - ./app:/var/www/laravel 8 | - ./logs/laravel:/var/www/laravel/storage/logs 9 | tty: true 10 | db: 11 | image: mariadb:latest 12 | environment: 13 | MYSQL_ROOT_PASSWORD: toor 14 | MYSQL_DATABASE: laravel 15 | TEST_DB_NAME: laravel_test 16 | MYSQL_USER: laravel 17 | MYSQL_PASSWORD: laravel 18 | depends_on: 19 | - application 20 | redis: 21 | image: redis:alpine 22 | php: 23 | build: php7-fpm 24 | environment: 25 | MAIL_ENCRYPTION: 0 26 | MAIL_PRETEND: 0 27 | MAIL_USERNAME: null 28 | MAIL_PASSWORD: null 29 | volumes_from: 30 | - application 31 | depends_on: 32 | - application 33 | - db 34 | - redis 35 | links: 36 | - db 37 | - redis 38 | nginx: 39 | build: nginx 40 | links: 41 | - php 42 | volumes_from: 43 | - application 44 | volumes: 45 | - ./logs/nginx/:/var/log/nginx 46 | depends_on: 47 | - db 48 | - php 49 | - redis 50 | - mailcatcher 51 | ports: 52 | - 80:80 53 | elk: 54 | image: willdurand/elk 55 | volumes: 56 | - ./elk/logstash:/etc/logstash 57 | - ./elk/logstash/patterns:/opt/logstash/patterns 58 | volumes_from: 59 | - application 60 | - php 61 | - nginx 62 | ports: 63 | - 81:80 64 | mailcatcher: 65 | build: mailcatcher 66 | ports: 67 | - 82:1080 68 | - 25:1025 69 | -------------------------------------------------------------------------------- /docs/container-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/purinda/docker-laravel/c6cf9e5653a9b6e71a116ed620986462ed67a487/docs/container-architecture.png -------------------------------------------------------------------------------- /elk/logstash/logstash.conf: -------------------------------------------------------------------------------- 1 | input { 2 | file { 3 | type => "nginx_access" 4 | path => "/var/log/nginx/laravel-access.log" 5 | start_position => beginning 6 | } 7 | file { 8 | type => "nginx_error" 9 | path => "/var/log/nginx/laravel-error.log" 10 | start_position => beginning 11 | } 12 | file { 13 | type => "laravel_logs" 14 | path => "/var/www/laravel/storage/logs/lumen.log" 15 | start_position => beginning 16 | } 17 | } 18 | 19 | filter { 20 | if [type] == "nginx_access" { 21 | grok { 22 | patterns_dir => "./patterns" 23 | match => { "message" => "%{NGINXACCESS}"} 24 | } 25 | } 26 | 27 | if [type] == "laravel_logs" { 28 | grok { 29 | match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} %{DATA:environment}\.%{LOGLEVEL:severity}: %{GREEDYDATA:message}" } 30 | } 31 | 32 | multiline { 33 | pattern => "^\[" 34 | what => "previous" 35 | negate => true 36 | } 37 | } 38 | } 39 | 40 | output { 41 | elasticsearch { 42 | host => "localhost" 43 | cluster => "logstash" 44 | } 45 | } -------------------------------------------------------------------------------- /elk/logstash/patterns/default.conf: -------------------------------------------------------------------------------- 1 | USERNAME [a-zA-Z0-9._-]+ 2 | USER %{USERNAME} 3 | INT (?:[+-]?(?:[0-9]+)) 4 | BASE10NUM (?[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+))) 5 | NUMBER (?:%{BASE10NUM}) 6 | BASE16NUM (?(?"(?>\\.|[^\\"]+)+"|""|(?>'(?>\\.|[^\\']+)+')|''|(?>`(?>\\.|[^\\`]+)+`)|``)) 17 | UUID [A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12} 18 | # Networking 19 | MAC (?:%{CISCOMAC}|%{WINDOWSMAC}|%{COMMONMAC}) 20 | CISCOMAC (?:(?:[A-Fa-f0-9]{4}\.){2}[A-Fa-f0-9]{4}) 21 | WINDOWSMAC (?:(?:[A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}) 22 | COMMONMAC (?:(?:[A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}) 23 | IPV6 ((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)? 24 | IPV4 (?/(?>[\w_%!$@:.,-]+|\\.)*)+ 33 | TTY (?:/dev/(pts|tty([pq])?)(\w+)?/?(?:[0-9]+)) 34 | WINPATH (?>[A-Za-z]+:|\\)(?:\\[^\\?*]*)+ 35 | URIPROTO [A-Za-z]+(\+[A-Za-z+]+)? 36 | URIHOST %{IPORHOST}(?::%{POSINT:port})? 37 | # uripath comes loosely from RFC1738, but mostly from what Firefox 38 | # doesn't turn into %XX 39 | URIPATH (?:/[A-Za-z0-9$.+!*'(){},~:;=@#%_\-]*)+ 40 | #URIPARAM \?(?:[A-Za-z0-9]+(?:=(?:[^&]*))?(?:&(?:[A-Za-z0-9]+(?:=(?:[^&]*))?)?)*)? 41 | URIPARAM \?[A-Za-z0-9$.+!*'|(){},~@#%&/=:;_?\-\[\]]* 42 | URIPATHPARAM %{URIPATH}(?:%{URIPARAM})? 43 | URI %{URIPROTO}://(?:%{USER}(?::[^@]*)?@)?(?:%{URIHOST})?(?:%{URIPATHPARAM})? 44 | # Months: January, Feb, 3, 03, 12, December 45 | MONTH \b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b 46 | MONTHNUM (?:0?[1-9]|1[0-2]) 47 | MONTHNUM2 (?:0[1-9]|1[0-2]) 48 | MONTHDAY (?:(?:0[1-9])|(?:[12][0-9])|(?:3[01])|[1-9]) 49 | # Days: Monday, Tue, Thu, etc... 50 | DAY (?:Mon(?:day)?|Tue(?:sday)?|Wed(?:nesday)?|Thu(?:rsday)?|Fri(?:day)?|Sat(?:urday)?|Sun(?:day)?) 51 | # Years? 52 | YEAR (?>\d\d){1,2} 53 | HOUR (?:2[0123]|[01]?[0-9]) 54 | MINUTE (?:[0-5][0-9]) 55 | # '60' is a leap second in most time standards and thus is valid. 56 | SECOND (?:(?:[0-5]?[0-9]|60)(?:[:.,][0-9]+)?) 57 | TIME (?!<[0-9])%{HOUR}:%{MINUTE}(?::%{SECOND})(?![0-9]) 58 | # datestamp is YYYY/MM/DD-HH:MM:SS.UUUU (or something like it) 59 | DATE_US %{MONTHNUM}[/-]%{MONTHDAY}[/-]%{YEAR} 60 | DATE_EU %{MONTHDAY}[./-]%{MONTHNUM}[./-]%{YEAR} 61 | ISO8601_TIMEZONE (?:Z|[+-]%{HOUR}(?::?%{MINUTE})) 62 | ISO8601_SECOND (?:%{SECOND}|60) 63 | TIMESTAMP_ISO8601 %{YEAR}-%{MONTHNUM}-%{MONTHDAY}[T ]%{HOUR}:?%{MINUTE}(?::?%{SECOND})?%{ISO8601_TIMEZONE}? 64 | DATE %{DATE_US}|%{DATE_EU} 65 | DATESTAMP %{DATE}[- ]%{TIME} 66 | TZ (?:[PMCE][SD]T|UTC) 67 | DATESTAMP_RFC822 %{DAY} %{MONTH} %{MONTHDAY} %{YEAR} %{TIME} %{TZ} 68 | DATESTAMP_RFC2822 %{DAY}, %{MONTHDAY} %{MONTH} %{YEAR} %{TIME} %{ISO8601_TIMEZONE} 69 | DATESTAMP_OTHER %{DAY} %{MONTH} %{MONTHDAY} %{TIME} %{TZ} %{YEAR} 70 | DATESTAMP_EVENTLOG %{YEAR}%{MONTHNUM2}%{MONTHDAY}%{HOUR}%{MINUTE}%{SECOND} 71 | # Syslog Dates: Month Day HH:MM:SS 72 | SYSLOGTIMESTAMP %{MONTH} +%{MONTHDAY} %{TIME} 73 | PROG (?:[\w._/%-]+) 74 | SYSLOGPROG %{PROG:program}(?:\[%{POSINT:pid}\])? 75 | SYSLOGHOST %{IPORHOST} 76 | SYSLOGFACILITY <%{NONNEGINT:facility}.%{NONNEGINT:priority}> 77 | HTTPDATE %{MONTHDAY}/%{MONTH}/%{YEAR}:%{TIME} %{INT} 78 | # Shortcuts 79 | QS %{QUOTEDSTRING} 80 | # Log formats 81 | SYSLOGBASE %{SYSLOGTIMESTAMP:timestamp} (?:%{SYSLOGFACILITY} )?%{SYSLOGHOST:logsource} %{SYSLOGPROG}: 82 | COMMONAPACHELOG %{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] "(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}|-) 83 | COMBINEDAPACHELOG %{COMMONAPACHELOG} %{QS:referrer} %{QS:agent} 84 | # Log Levels 85 | LOGLEVEL ([Aa]lert|ALERT|[Tt]race|TRACE|[Dd]ebug|DEBUG|[Nn]otice|NOTICE|[Ii]nfo|INFO|[Ww]arn?(?:ing)?|WARN?(?:ING)?|[Ee]rr?(?:or)?|ERR?(?:OR)?|[Cc]rit?(?:ical)?|CRIT?(?:ICAL)?|[Ff]atal|FATAL|[Ss]evere|SEVERE|EMERG(?:ENCY)?|[Ee]merg(?:ency)?) -------------------------------------------------------------------------------- /elk/logstash/patterns/nginx.conf: -------------------------------------------------------------------------------- 1 | NGINXACCESS %{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] "(?:%{WORD:verb} %{URIPATHPARAM:request}(?: HTTP/%{NUMBER:httpversion})?|-)" %{NUMBER:response} (?:%{NUMBER:bytes}|-) "(?:%{URI:referrer}|-)" %{QS:agent} %{NUMBER:request_time} %{NUMBER:upstream_response_time} %{NUMBER:gzip_ratio} (?:%{WORD:cache_hit}|-)%{GREEDYDATA} -------------------------------------------------------------------------------- /mailcatcher/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.2.3 2 | 3 | EXPOSE 1025 1080 4 | RUN gem install mailcatcher -v 0.5.12 5 | 6 | CMD mailcatcher -f --http-ip=0.0.0.0 --smtp-ip=0.0.0.0 7 | -------------------------------------------------------------------------------- /nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | 3 | RUN apt update && apt install -y \ 4 | nginx 5 | 6 | ADD nginx.conf /etc/nginx/ 7 | ADD laravel.conf /etc/nginx/sites-available/ 8 | 9 | RUN ln -s /etc/nginx/sites-available/laravel.conf /etc/nginx/sites-enabled/laravel 10 | RUN rm /etc/nginx/sites-enabled/default 11 | 12 | RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf 13 | 14 | RUN usermod -u 1000 www-data 15 | 16 | CMD ["nginx"] 17 | 18 | EXPOSE 80 19 | EXPOSE 443 20 | -------------------------------------------------------------------------------- /nginx/laravel.conf: -------------------------------------------------------------------------------- 1 | # App virtual host configuration 2 | server { 3 | listen 80; 4 | server_name app.dev; 5 | root /var/www/laravel/public; 6 | 7 | index index.html index.htm index.php; 8 | 9 | auth_basic off; 10 | 11 | charset utf-8; 12 | 13 | location / { 14 | try_files $uri $uri/ /index.php?$query_string; 15 | } 16 | 17 | location = /favicon.ico { access_log off; log_not_found off; } 18 | location = /robots.txt { access_log off; log_not_found off; } 19 | 20 | access_log /var/log/nginx/laravel-access.log; 21 | error_log /var/log/nginx/laravel-error.log error; 22 | 23 | sendfile off; 24 | 25 | location ~ \.php$ { 26 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 27 | fastcgi_pass php-upstream; 28 | fastcgi_index index.php; 29 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 30 | include fastcgi_params; 31 | } 32 | 33 | location ~ /\.ht { 34 | deny all; 35 | } 36 | } -------------------------------------------------------------------------------- /nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | user www-data; 2 | worker_processes 4; 3 | pid /run/nginx.pid; 4 | 5 | events { 6 | worker_connections 2048; 7 | multi_accept on; 8 | use epoll; 9 | } 10 | 11 | http { 12 | server_tokens off; 13 | sendfile on; 14 | tcp_nopush on; 15 | tcp_nodelay on; 16 | keepalive_timeout 15; 17 | types_hash_max_size 2048; 18 | include /etc/nginx/mime.types; 19 | default_type application/octet-stream; 20 | access_log off; 21 | error_log off; 22 | gzip on; 23 | gzip_disable "msie6"; 24 | include /etc/nginx/conf.d/*.conf; 25 | include /etc/nginx/sites-enabled/*; 26 | open_file_cache max=100; 27 | } 28 | 29 | daemon off; 30 | -------------------------------------------------------------------------------- /php7-fpm/Dockerfile: -------------------------------------------------------------------------------- 1 | # See https://github.com/docker-library/php/blob/4677ca134fe48d20c820a19becb99198824d78e3/7.0/fpm/Dockerfile 2 | FROM php:7.0-fpm 3 | 4 | MAINTAINER Purinda Gunasekara 5 | 6 | RUN apt-get update && apt-get install -y \ 7 | git \ 8 | libmcrypt-dev \ 9 | unzip 10 | 11 | # Install Composer 12 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 13 | RUN composer --version 14 | 15 | # Set timezone to UTC 16 | RUN rm /etc/localtime 17 | RUN ln -s /usr/share/zoneinfo/UTC /etc/localtime 18 | RUN "date" 19 | 20 | # Type docker-php-ext-install to see available extensions 21 | RUN docker-php-ext-install pdo pdo_mysql mcrypt 22 | 23 | WORKDIR /var/www/laravel 24 | -------------------------------------------------------------------------------- /setup-phpunit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eo pipefail 3 | SCRIPT=`basename "$0"` 4 | 5 | # 6 | # Following condition determines the behaviour of the script. 7 | # - If NOT within the container, script copies itself to the container 8 | # - If within the container, script runs the commands 9 | # 10 | if [ -z "$MARIADB_MAJOR" ]; then 11 | # Copy the setup command to the database container and run 12 | DB_CONTAINER=$(docker-compose ps | grep db | cut -d " " -f1) 13 | docker cp $SCRIPT "$DB_CONTAINER:/" 14 | docker-compose exec db bash /$SCRIPT 15 | 16 | echo Laravel db setup installed and ran successfully 17 | else 18 | # Write default mysql params for easier access without specifying mysql connection params in the CLI 19 | { \ 20 | echo "[client]"; \ 21 | echo "host='localhost'"; \ 22 | echo "database=$MYSQL_DATABASE"; \ 23 | echo "password=$MYSQL_ROOT_PASSWORD"; \ 24 | } >> /root/.my.cnf 25 | 26 | # Setup Laravel test database and grant permissions 27 | if [ "$TEST_DB_NAME" ]; then 28 | mysql -e "CREATE DATABASE IF NOT EXISTS \`$TEST_DB_NAME\`"; 29 | 30 | if [ "$TEST_DB_NAME" ]; then 31 | mysql -e "GRANT ALL ON \`$TEST_DB_NAME\`.* TO '$MYSQL_USER'@'%'"; 32 | fi 33 | fi 34 | 35 | if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then 36 | mysql -e "CREATE USER IF NOT EXISTS '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD'"; 37 | 38 | if [ "$MYSQL_DATABASE" ]; then 39 | mysql -e "GRANT ALL ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'@'%'"; 40 | fi 41 | 42 | mysql -e 'FLUSH PRIVILEGES'; 43 | fi 44 | fi 45 | --------------------------------------------------------------------------------