Refer to the one that was originally made (Paku)
-Created with the image of php7.4 / mysql8 / nginx1.19 ・ Created with the project name sampleproject ・ Confirm with Docker Desktop for Windows
laravel
├ docker-compose.yml
├ docker
│ ├ php
│ │ ├ php.ini
│ │ └ Dockerfile
│ └ nginx
│ └ default.conf
└ server
docker-compose.yml
version: '3'
services:
laravel_php:
container_name: laravel_php
build: ./docker/php
volumes:
- ./server:/var/www
laravel_nginx:
image: nginx:1.19
container_name: laravel_nginx
ports:
- 80:80
volumes:
- ./server:/var/www
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- laravel_php
laravel_db:
image: mysql:8.0
container_name: laravel_db
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: sampleproject
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbpass
TZ: 'Asia/Tokyo'
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
volumes:
- ./docker/db/data:/var/lib/mysql
- ./docker/db/my.cnf:/etc/mysql/conf.d/my.cnf
- ./docker/db/sql:/docker-entrypoint-initdb.d
ports:
- 3306:3306
../docker/nginx/default.conf
[Date]
date.timezone = "Asia/Tokyo"
[mbstring]
mbstring.internal_encoding = "UTF-8"
mbstring.language = "Japanese"
../docker/php/Dockerfile
FROM php:7.4-fpm
COPY php.ini /usr/local/etc/php/
RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y zlib1g-dev && apt-get install -y libzip-dev
RUN docker-php-ext-install pdo_mysql zip
COPY --from=composer /usr/bin/composer /usr/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /composer
ENV PATH $PATH:/composer/vendor/bin
WORKDIR /var/www
RUN composer global require "laravel/installer"
../docker/nginx/default.conf
server {
index index.php index.html;
server_name localhost;
root /var/www/sampleproject/public;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass laravel_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;
}
}
docker-compose up -d
docker exec -ti laravel_php bash
In the container (version 6 creation command)
composer create-project "laravel/laravel=6.*" sampleproject
After creating the project (inside the container)
cd sampleproject
chmod -R 777 storage
chmod -R 777 bootstrap/cache
php artisan serve
Edit .env (under project folder)
..env
DB_CONNECTION=mysql
DB_HOST=laravel_db
DB_PORT=3306
DB_DATABASE=sampleproject
DB_USERNAME=dbuser
DB_PASSWORD=dbpass
Connection confirmation
php argisan migrate
Recommended Posts