フォルダ構成
│ docker-compose.yml
└─docker
├─php
│ dockerfile
│ php.ini
└─nginx
default.conf
docker-compose.yml
version: '3'
services:
php:
container_name: php
build: ./docker/php
volumes:
- ./server:/var/www
nginx:
image: nginx
container_name: nginx
ports:
- 8080:80
volumes:
- ./server:/var/www
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
db:
image: mysql:5.7
container_name: db-host
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: database
MYSQL_USER: docker
MYSQL_PASSWORD: docker
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
phpのdockerfile
FROM php:7.2-fpm
COPY php.ini /usr/local/etc/php/
RUN apt-get update \
&& apt-get install -y zlib1g-dev mariadb-client \
&& docker-php-ext-install zip pdo_mysql
#Composer install
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"
php.ini
[Date]
date.timezone = "Asia/Tokyo"
[mbstring]
mbstring.internal_encoding = "UTF-8"
mbstring.language = "Japanese"
nginxのdefault.conf
server {
listen 80;
index index.php index.html;
root /var/www/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;
}
}
ビルド
docker-compose build
docker起動
docker-compose up -d
phpコンテナに入る
docker-compose exec php bash
Laravelプロジェクト作成
composer create-project --prefer-dist laravel/laravel ./
/var/www/storage配下のフォルダのアクセス権を777にする
chmod -R 777 storage/
確認
http://localhost:8080/にアクセスしてlaravelページが表示されればOK