dockerfile
FROM php:7.4-apache
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
vim \
libonig-dev \
libzip-dev
RUN docker-php-ext-install \
pdo_mysql \
mysqli \
mbstring \
zip
RUN apt-get install -y curl git unzip
# https://getcomposer.org/download/ に差し替える
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { 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');"
# https://getcomposer.org/download/ に差し替える ここまで
# mvでなぜかディレクトリが作成されてしまうのでシンボリックリンクを貼る
RUN mv ./composer.phar $(dirname $(which php))
RUN chmod +x $(dirname $(which php))/composer.phar
RUN ln -s $(dirname $(which php))/composer.phar /usr/bin/composer
RUN composer global require laravel/installer
RUN a2enmod rewrite
ENV PATH $PATH:/root/.composer/vendor/bin
実行
$ docker compose build
$ docker compose up -d
$ docker compose exec php sh
# laravel new stock
_ _
| | | |
| | __ _ _ __ __ ___ _____| |
| | / _` | '__/ _` \ \ / / _ \ |
| |___| (_| | | | (_| |\ V / __/ |
|______\__,_|_| \__,_| \_/ \___|_|
参考