目次

Docker環境に構築

Dockerのセットアップ

docker-compose.yml作成
# docker-compose.yml

version: '3.9'

services:
  app:
    build:
      context: <Dockerfileのディレクトリパス>
    container_name: breeze_app
    volumes:
      - <Laravelプロジェクトのパス>:/var/www/html
    ports:
      - "8000:80"
    environment:
      - TZ=Asia/Tokyo
    depends_on:
      - db

  db:
    image: mysql:8.0
    container_name: breeze_db
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_DATABASE: laravel_breeze
      MYSQL_ROOT_PASSWORD: <パスワード>
      MYSQL_USER: laravel_breeze
      MYSQL_PASSWORD: <パスワード>
      TZ: Asia/Tokyo
    volumes:
      - db_data:/var/lib/mysql
    expose:
      - 3306

volumes:
  db_data:
Dockerfile作成
# Dockerfile

FROM php:8.0-fpm

RUN apt-get update && apt-get upgrade -y && apt-get install -y unzip libzip-dev

RUN docker-php-ext-install pdo_mysql zip
RUN docker-php-ext-enable pdo_mysql zip
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-enable pdo_mysql

RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get install -y nodejs

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /var/www/html

ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_HOME /composer
ENV PATH $PATH:/composer/vendor/bin

RUN echo "Asia/Tokyo" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata

RUN apt-get install -y locales
RUN sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
RUN locale-gen

ENV LANG ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja
ENV LC_ALL ja_JP.UTF-8

EXPOSE 80
コンテナ作成
$ docker-compose up -d --build

Laravelプロジェクト作成

$ docker exec -it breeze_app bash

# コンテナの中に入る

$ composer global require laravel/installer
$ composer create-project --prefer-dist laravel/laravel=9.* .
$ chmod -R a+w storage bootstrap/cache public