Help us understand the problem. What is going on with this article?

Laravel 5.8 + dockerで新規プロジェクトを作成する

dockerコンテナでlaravelのスタータープロジェクトを作成します。

手順

1. ベースイメージの作成

php7.2をベースに composer + laravel 5.8のイメージを作成する

FROM php:7.2-fpm
COPY php.ini /usr/local/etc/php/

RUN apt-get update && \
    apt-get install -y \
    libpq-dev \
    zlib1g-dev && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

RUN pecl install xdebug && docker-php-ext-enable xdebug
RUN docker-php-ext-install zip pdo

# install composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer

# setup composer
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /composer
ENV PATH $PATH:/composer/vendor/bin
ENV PATH $PATH:/app/vendor/bin

# instal laravel
RUN composer global require "laravel/installer"
$ docker build . -t laravel-base

2. 作成したベースイメージでlaravelアプリケーションを生成する

$ docker run -w / -it laravel-base bash
(laravel-base) # laravel new app
$ docker cp <container id>:/app .

さっきビルドしたlaravel-baseを使って laravel new app コマンドを実行。
出力されたファイルをホストPCにコピーします。

3. 実行

$ docker run -v app:/app -w /app -p 8000:8000 -it laravel-app php artisan serve --port 8000
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away