Skip to content

Instantly share code, notes, and snippets.

@tuantranf
Last active December 11, 2018 10:32
Show Gist options
  • Save tuantranf/55ca557adcc5c05c049b2e5f7f4123a2 to your computer and use it in GitHub Desktop.
Save tuantranf/55ca557adcc5c05c049b2e5f7f4123a2 to your computer and use it in GitHub Desktop.
Laravel mysql docker composer template

Laravel mysql docker composer template

  1. Make docker directory inside your application directory
  2. Save docker-compose.yml, app.dockerfile, nginx.conf to docker directory
  3. Change directory to dockder
  4. docker-composer up
FROM php:7.2-fpm
LABEL maintainer="[email protected]"
RUN apt-get update && apt-get install -y \
build-essential \
mysql-client \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Installing extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl bcmath opcache \
&& docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ \
&& docker-php-ext-install gd
# Installing composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Setting locales
RUN echo en_US.UTF-8 UTF-8 > /etc/locale.gen && locale-gen
# Allow container to write on host
RUN usermod -u 1000 www-data
WORKDIR /var/www/html
version: '3'
services:
mysql:
image: mysql:5.7
ports:
- "6306:3306"
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: db-local
nginx:
image: nginx
ports:
- "8000:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:cached
links:
- app
app:
build:
context: ../
dockerfile: docker/app.dockerfile
working_dir: /var/www/html
volumes:
- ../:/var/www/html
environment:
APP_ENV: local
APP_DEBUG: "true"
APP_KEY: base64:1T99e3tXq0GbpGx2ht8IV56zWlA7wQuG0+pHy7f9CFU=
DB_HOST: mysql
DB_DATABASE: db-local
DB_USERNAME: root
DB_PASSWORD: password
CACHE_DRIVER: file
SESSION_DRIVER: file
QUEUE_DRIVER: sync
tty: true
depends_on:
- mysql
volumes:
db-data:
server {
listen 80;
index index.php index.html index.htm;
root /var/www/html/public; # default Laravel's entry point for all requests
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass app:9000; # address of a fastCGI server
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment