Docker PHPの各種バージョンの違いについて調べてみる

adventar.org

Day-3です。

カレンダーを見ると、「docker phpの各種バージョンの違いについて調べてみる」という事でネタが設定されていました。
これに従ってまいりましょう。
はて・・・

PHPの公式Dockerイメージ

https://hub.docker.com/_/php/
これのことです。なのだけども、「長すぎて全文じゃないよ」って書いてあるので、READMEを見ましょう

github.com

こちらをいろいろと覗いてみようかな、というのが本日のエントリーです。

  1. stretch/cli
    • 7.3.0RC6-cli-stretch, 7.3-rc-cli-stretch, rc-cli-stretch, 7.3.0RC6-stretch, 7.3-rc-stretch, rc-stretch, 7.3.0RC6-cli, 7.3-rc-cli, rc-cli, 7.3.0RC6, 7.3-rc, rc (7.3-rc/stretch/cli/Dockerfile)
  2. stretch/apache
    • 7.3.0RC6-apache-stretch, 7.3-rc-apache-stretch, rc-apache-stretch, 7.3.0RC6-apache, 7.3-rc-apache, rc-apache (7.3-rc/stretch/apache/Dockerfile)
  3. stretch/fpm
    • 7.3.0RC6-fpm-stretch, 7.3-rc-fpm-stretch, rc-fpm-stretch, 7.3.0RC6-fpm, 7.3-rc-fpm, rc-fpm (7.3-rc/stretch/fpm/Dockerfile)
  4. stretch/zts
    • 7.3.0RC6-zts-stretch, 7.3-rc-zts-stretch, rc-zts-stretch, 7.3.0RC6-zts, 7.3-rc-zts, rc-zts (7.3-rc/stretch/zts/Dockerfile)
  5. alpine3.8/cli
    • 7.3.0RC6-cli-alpine3.8, 7.3-rc-cli-alpine3.8, rc-cli-alpine3.8, 7.3.0RC6-alpine3.8, 7.3-rc-alpine3.8, rc-alpine3.8, 7.3.0RC6-cli-alpine, 7.3-rc-cli-alpine, rc-cli-alpine, 7.3.0RC6-alpine, 7.3-rc-alpine, rc-alpine (7.3-rc/alpine3.8/cli/Dockerfile)
  6. alpine3.8/fpm
    • 7.3.0RC6-fpm-alpine3.8, 7.3-rc-fpm-alpine3.8, rc-fpm-alpine3.8, 7.3.0RC6-fpm-alpine, 7.3-rc-fpm-alpine, rc-fpm-alpine (7.3-rc/alpine3.8/fpm/Dockerfile)
  7. alpine3.8/zts
    • 7.3.0RC6-zts-alpine3.8, 7.3-rc-zts-alpine3.8, rc-zts-alpine3.8, 7.3.0RC6-zts-alpine, 7.3-rc-zts-alpine, rc-zts-alpine (7.3-rc/alpine3.8/zts/Dockerfile)

6種類。
「stretch or alpine」と「clit or apache or fpm or zts」の組み合わせですね。
ただし、alpine/apacheだけない模様*1

OS別

stretch

debian:stretch-slimをベースにしています。 https://hub.docker.com/_/debian/

stretchて?という方は gihyo.jp

alpine

alpine:3.8をベースにしています https://hub.docker.com/_/alpine/

alpine触ったことねぇ・・・というときには

yoshinorin.net

構成別

apache

これはDebianの方にしかない。

php/Dockerfile at ee78d7883237754eb68ffb281f5835f851797e05 · docker-library/php · GitHub

fpm

debian php/Dockerfile at ee78d7883237754eb68ffb281f5835f851797e05 · docker-library/php · GitHub

alpine php/Dockerfile at ee78d7883237754eb68ffb281f5835f851797e05 · docker-library/php · GitHub

cli

無印の php:7.3-rc もCLIとイメージを共同しているので、1番の素となるイメージがこれ!という感じかな・・・

debian php/Dockerfile at ee78d7883237754eb68ffb281f5835f851797e05 · docker-library/php · GitHub

alpine php/Dockerfile at ee78d7883237754eb68ffb281f5835f851797e05 · docker-library/php · GitHub

zts

ztsって何?は

qiita.com

debian php/Dockerfile at ee78d7883237754eb68ffb281f5835f851797e05 · docker-library/php · GitHub

alpine

php/Dockerfile at ee78d7883237754eb68ffb281f5835f851797e05 · docker-library/php · GitHub

どんなPHPですか?

alpine-fpmを見ると、ビルド時にこんな感じのオプションが渡されている

 && ./configure \
        --build="$gnuArch" \
        --with-config-file-path="$PHP_INI_DIR" \
        --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
        \
# make sure invalid --configure-flags are fatal errors intead of just warnings
        --enable-option-checking=fatal \
        \
# https://github.com/docker-library/php/issues/439
        --with-mhash \
        \
# --enable-ftp is included here because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236)
        --enable-ftp \
# --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195)
        --enable-mbstring \
# --enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself)
        --enable-mysqlnd \
# https://wiki.php.net/rfc/argon2_password_hash (7.2+)
        --with-password-argon2 \
# https://wiki.php.net/rfc/libsodium
        --with-sodium=shared \
        \
        --with-curl \
        --with-libedit \
        --with-openssl \
        --with-zlib \

この辺りのことが公式のdocに書いてあるわけで。

README§Image-Variantsのとこ。

php:-cli

「his variant contains the PHP CLI tool with default mods」であり「Note that all variants of php contain the PHP CLI (/usr/local/bin/php).」であると。 「使い捨てコンテナ、もしくは他の何かを作るときのベースイメージとして使ってね〜」ということ

php:-apache

「mod_php/mpm_preforkを利用するApacheのやつ」で「Debianベース」と。

document rootの変え方だったり、その他のconfの変更についてもこの docで言及されておりました

php:-fpm

fomコミコミバージョン。

php:-alpine

「人気のあるAlpine Linux projectをベースにしたもの」で「可能な限りサイズの小さなdocker imageがほしい!」ということであれば、使うべきだ・・!と説明されており。

その他のこと

php.iniとかをいじりたい

$PHP_INI_DIR というい環境変数がセットされているから、それを使えるよ!とのこと。 source

ん〜、カレンダーにネタ登録したときはもう少し面白い掘り下げ方ができると思ったのだけど。
ただコピペしました!みたいなところで終わってしまった・・

*1:ちなみに訳あって私はalpine/apacheを欲しています