LoginSignup
0
0

More than 1 year has passed since last update.

Laravel docker buildする用のDockerFileの書き方

Posted at

LaravelのコンテナをビルドしてECRにpushする場合など

よく見かける開発用のdocker構成だと、volumeがリンクなので、そのままbuildしても何もファイルがない、という状態になる。

また、composer installなどは手動でやる前提のままになっているのでdocker build=laravelがそのまま動く状態になっていない。

よって、DockerFileを少し変更する必要があった。

DockerFile Example

FROM php:7.4-fpm-buster
SHELL ["/bin/bash", "-oeux", "pipefail", "-c"]

# timezone environment
ENV LANG=C.UTF-8 \
    LANGUAGE=en_US: \
    LC_ALL=C.UTF-8 \
    TZ=UTC

# ini and conf
COPY ./infra/docker/php/zzz-www.conf /usr/local/etc/php-fpm.d/zzz-www.conf
COPY ./infra/docker/php/php.ini.production /usr/local/etc/php/php.ini

# ここでローカルのlaravelのディレクトリをコピーする
COPY ./local_develop_BackEnd /work/backend

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    libzip-dev \
    zip \
    unzip \
    vim

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install intl pdo zip gd pdo_mysql mbstring xml bcmath opcache

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN composer config -g process-timeout 3600 && \
    composer config -g repos.packagist composer https://packagist.org

RUN apt-get update

# Set working directory
WORKDIR /work/backend

# ローカルフォルダをコピーしているので、不要なキャッシュなどをクリアする
RUN php artisan cache:clear
RUN rm -rf vendor 
RUN rm -rf bootstrap/cache/*
RUN rm composer.lock

# laravelの初期インストールを行う。
RUN composer install --optimize-autoloader --no-dev
RUN cp .env.production .env
RUN chmod -R 777 storage bootstrap/cache
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0