Skip to content

Instantly share code, notes, and snippets.

@rkd-me
Last active May 10, 2020 01:06
Show Gist options
  • Save rkd-me/d5836a150ad04c99bb2fa3482e3866ec to your computer and use it in GitHub Desktop.
Save rkd-me/d5836a150ad04c99bb2fa3482e3866ec to your computer and use it in GitHub Desktop.
Laravel Development Environment Boilerplate for Docker Compose
  1. Create two folders called mysql, nginx and src.
  2. Create nginx settings in nginx\default.conf.
  3. Create docker settings in dockerfile for php image build schema.
  4. Copy and Set correct values in boilerplate called docker-compose.yml
  5. Build and Run containers by typing
docker-compose up -d --build
  1. Stop containers using
docker-compose stop
docker-compose down
server
{
listen 80;
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: database-name
MYSQL_USER: user-name
MYSQL_PASSWORD: secret-password
MYSQL_ROOT_PASSWORD: secret-password
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
composer:
image: composer:latest
container_name: composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
networks:
- laravel
npm:
image: node:13.7
container_name: npm
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
entrypoint: ['npm']
networks:
- laravel
artisan:
build:
context: .
dockerfile: dockerfile
container_name: artisan
volumes:
- ./src:/var/www/html
depends_on:
- mysql
working_dir: /var/www/html
entrypoint: ['/var/www/html/artisan']
networks:
- laravel
FROM php:7.2-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment