Last active
September 13, 2024 14:17
-
-
Save kevinyan815/fa0760902d29f19a4213b4a16fe0501b to your computer and use it in GitHub Desktop.
compose template for laravel docker project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM nginx:1.10 | |
ADD vhost.conf /etc/nginx/conf.d/default.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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