Skip to content

Instantly share code, notes, and snippets.

@kevinyan815
Last active February 21, 2023 10:22
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kevinyan815/fa0760902d29f19a4213b4a16fe0501b to your computer and use it in GitHub Desktop.
Save kevinyan815/fa0760902d29f19a4213b4a16fe0501b to your computer and use it in GitHub Desktop.
compose template for laravel docker project
version: '2'
services:
# The Application
app:
build:
context: ./
dockerfile: php-fpm.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
# laravel uses Dotenv to set and load environment variables,by default it will not
# overwrite existing environment variables. So we set env variables for app container here
# then laravel will use these env values instead of the same env variables defined in .env file.
- "DB_PORT=3306"
- "DB_HOST=database"
composer:
restart: 'no'
image: prooph/composer:7.1
working_dir: /var/www
command: install
volumes:
- .:/var/www
# The Nginx Server
nginx:
build:
context: ./
dockerfile: nginx.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8080:80
# The Database
database:
image: mysql:5.7
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"
volumes:
dbdata:
FROM nginx:1.10
ADD vhost.conf /etc/nginx/conf.d/default.conf
FROM php:7.1.22-fpm
# Update packages
RUN apt-get update
# Install PHP and composer dependencies
RUN apt-get install -qq git curl libmcrypt-dev libjpeg-dev libpng-dev libfreetype6-dev libbz2-dev
# Clear out the local repository of retrieved package files
RUN apt-get clean
# Install needed extensions
# Here you can install any other extension that you need during the test and deployment process
RUN docker-php-ext-install pdo pdo_mysql mcrypt zip gd
#Issue commands into container
#
# portion 1: docekr-compose exec command
#
# portion 2: the name of service as defined in docker-compose.yml
#
# portion 3: the command to execute in container just as you would normally run on your local machine
#
docker-compose exec app php artisan key:generate
docker-compose exec app php artisan optimize
docker-compose exec app php artisan migrate
docker-compose exec app php artisan make:auth
# then visit http://localhost:8080/login, you will find it works like a charm!
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment