php-common-dev/docs/docker-php.md
2025-04-03 09:04:07 +09:00

76 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

* php:*-apache サイズ:約350MB以上
* php:*-cli-alpine サイズ:約350MB以上
* php:*-fpm-alpine
## `php:*-apache + composer`による構築
```dockerfile
FROM php:8.3-apache
# 必要最低限のインストール
RUN apt-get update && apt-get install -y --no-install-recommends \
libyaml-dev \
unzip \
curl \
&& rm -rf /var/lib/apt/lists/*
# Composerのインストール公式手順
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# xdebugのインストールバージョン指定せず最新版
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
# yaml extensionのインストール
RUN pecl install yaml \
&& docker-php-ext-enable yaml
```
### `PHP-FPM + composer + Nginx`の構成
```dockerfile
FROM php:8.3-fpm-alpine
# 必要パッケージのインストール
RUN apk add --no-cache \
libyaml-dev \
imagemagick \
imagemagick-dev \
libheif \
unzip \
curl \
autoconf \
gcc \
g++ \
make \
&& pecl install yaml xdebug \
&& docker-php-ext-enable yaml xdebug \
&& apk del autoconf gcc g++ make # ビルド系は後で削除して軽量化
# Composerの追加公式composerイメージから取得
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
WORKDIR /var/www/html
```
### GDの対応
```Dockerfile
# 必要パッケージを追加
RUN apk add --no-cache \
libpng-dev \
libjpeg-turbo-dev \
freetype-dev \
...
# GDをビルドして有効化enable不要
RUN docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
&& docker-php-ext-install gd
```