GD を使える php:5.6-apache の Dockerfile 内容
FROM php:5.6-apache RUN apt-get update && apt-get install -y \ libfreetype6-dev \ libjpeg62-turbo-dev \ libpng-dev \ && docker-php-ext-install gd pdo_mysql mysqli mbstring \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && a2enmod rewrite COPY ./php.ini /usr/local/etc/php/ COPY ./000-default.conf /etc/apache2/sites-available/000-default.conf
ポイント
- docker-php-ext-install gd と GD を指定するだけではダメ、不足している。
- libfreetype6-dev, libjpeg62-turbo-dev, libpng-dev を事前に apt-get install する必要がある。
以上を行わず、単に docker-php-ext-install gd とした場合、docker build 時に次のようなエラーとなりました。
$ docker-compose build Building db Step 1/2 : FROM mysql:5.7 ---> 43b029b6b640 Step 2/2 : COPY ./config-file.cnf /etc/mysql/conf.d/ ---> Using cache ---> 28c7fd101544 Successfully built 28c7fd101544 Successfully tagged docker-l-a24-m56-p56_db:latest Building appweb Step 1/4 : FROM php:5.6-apache ---> 12398af6f4de Step 2/4 : RUN apt-get update && docker-php-ext-install gd pdo_mysql mysqli mbstring && apt-get clean && rm -rf /var/lib/apt/lists/* && a2enmod rewrite ---> Running in e4793ea4f2e7 Get:1 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB] Ign:2 http://cdn-fastly.deb.debian.org/debian stretch InRelease Get:4 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [391 kB] Get:3 http://cdn-fastly.deb.debian.org/debian stretch-updates InRelease [91.0 kB] Get:5 http://cdn-fastly.deb.debian.org/debian stretch Release [118 kB] Get:6 http://cdn-fastly.deb.debian.org/debian stretch-updates/main amd64 Packages [5148 B] Get:7 http://cdn-fastly.deb.debian.org/debian stretch Release.gpg [2434 B] Get:8 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 Packages [7099 kB] Fetched 7801 kB in 7s (1047 kB/s) Reading package lists... Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking for cc... cc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether cc accepts -g... yes checking for cc option to accept ISO C89... none needed checking how to run the C preprocessor... cc -E checking for icc... no checking for suncc... no checking whether cc understands -c and -o together... yes checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu checking for PHP prefix... /usr/local checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20131226 checking for PHP installed headers prefix... /usr/local/include/php checking if debug is enabled... no checking if zts is enabled... no checking for re2c... re2c checking for re2c version... 0.16 (ok) checking for gawk... no checking for nawk... nawk checking if nawk is broken... no checking for GD support... yes, shared checking for the location of libvpx... no checking for the location of libjpeg... no checking for the location of libpng... no checking for the location of libz... no checking for the location of libXpm... no checking for FreeType 2... no checking for T1lib support... no checking whether to enable truetype string function in GD... no checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-vpx-dir=<DIR> If configure fails try --with-jpeg-dir=<DIR> configure: error: png.h not found. ERROR: Service 'appweb' failed to build: The command '/bin/sh -c apt-get update && docker-php-ext-install gd pdo_mysql mysqli mbstring && apt-get clean && rm -rf /var/lib/apt/lists/* && a2enmod rewrite' returned a non-zero code: 1 $
おまけ
Debian の Docker イメージ debian:9.5 (本投稿時の最新版) で PHP をインストール後、php-gd をインストールしようとすると、次のようになりました。
Dockerfile に指定したそれぞれのパッケージ
- libfreetype6-dev
- libjpeg62-turbo-dev
- libpng-dev
上記そのものはインストールされませんが、上記のものはすべて dev なので、おそらく上記のものは全て含んだパッケージなのでしょう。
root@64cbb76c3da3:/# # PHP GD をインストール root@64cbb76c3da3:/# apt install php-gd Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: fontconfig-config fonts-dejavu-core libfontconfig1 libfreetype6 libgd3 libjbig0 libjpeg62-turbo libpng16-16 libtiff5 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 php7.0-gd Suggested packages: libgd-tools The following NEW packages will be installed: fontconfig-config fonts-dejavu-core libfontconfig1 libfreetype6 libgd3 libjbig0 libjpeg62-turbo libpng16-16 libtiff5 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 php-gd php7.0-gd 0 upgraded, 18 newly installed, 0 to remove and 0 not upgraded. Need to get 4455 kB of archives. After this operation, 11.3 MB of additional disk space will be used. Do you want to continue? [Y/n] Get:1 http://deb.debian.org/debian stretch/main amd64 libxau6 amd64 1:1.0.8-1 [20.7 kB] Get:2 http://deb.debian.org/debian stretch/main amd64 fonts-dejavu-core all 2.37-1 [1068 kB] Get:3 http://deb.debian.org/debian stretch/main amd64 fontconfig-config all 2.11.0-6.7 [271 kB] Get:4 http://deb.debian.org/debian stretch/main amd64 libpng16-16 amd64 1.6.28-1 [280 kB] Get:5 http://deb.debian.org/debian stretch/main amd64 libfreetype6 amd64 2.6.3-3.2 [438 kB] Get:6 http://deb.debian.org/debian stretch/main amd64 libfontconfig1 amd64 2.11.0-6.7+b1 [331 kB] Get:7 http://deb.debian.org/debian stretch/main amd64 libjpeg62-turbo amd64 1:1.5.1-2 [134 kB] Get:8 http://deb.debian.org/debian stretch/main amd64 libjbig0 amd64 2.1-3.1+b2 [31.0 kB] Get:9 http://deb.debian.org/debian stretch/main amd64 libtiff5 amd64 4.0.8-2+deb9u2 [238 kB] Get:10 http://deb.debian.org/debian stretch/main amd64 libwebp6 amd64 0.5.2-1 [235 kB] Get:11 http://deb.debian.org/debian stretch/main amd64 libxdmcp6 amd64 1:1.1.2-3 [26.3 kB] Get:12 http://deb.debian.org/debian stretch/main amd64 libxcb1 amd64 1.12-1 [133 kB] Get:13 http://deb.debian.org/debian stretch/main amd64 libx11-data all 2:1.6.4-3 [290 kB] Get:14 http://deb.debian.org/debian stretch/main amd64 libx11-6 amd64 2:1.6.4-3 [747 kB] Get:15 http://deb.debian.org/debian stretch/main amd64 libxpm4 amd64 1:3.5.12-1 [49.1 kB] Get:16 http://deb.debian.org/debian stretch/main amd64 libgd3 amd64 2.2.4-2+deb9u2 [132 kB] Get:17 http://deb.debian.org/debian stretch/main amd64 php7.0-gd amd64 7.0.30-0+deb9u1 [27.0 kB] Get:18 http://deb.debian.org/debian stretch/main amd64 php-gd all 1:7.0+49 [5042 B] Fetched 4455 kB in 1s (2471 kB/s) debconf: delaying package configuration, since apt-utils is not installed Selecting previously unselected package libxau6:amd64. (Reading database ... 9862 files and directories currently installed.) Preparing to unpack .../00-libxau6_1%3a1.0.8-1_amd64.deb ... Unpacking libxau6:amd64 (1:1.0.8-1) ... Selecting previously unselected package fonts-dejavu-core. Preparing to unpack .../01-fonts-dejavu-core_2.37-1_all.deb ... Unpacking fonts-dejavu-core (2.37-1) ... Selecting previously unselected package fontconfig-config. Preparing to unpack .../02-fontconfig-config_2.11.0-6.7_all.deb ... Unpacking fontconfig-config (2.11.0-6.7) ... Selecting previously unselected package libpng16-16:amd64. Preparing to unpack .../03-libpng16-16_1.6.28-1_amd64.deb ... Unpacking libpng16-16:amd64 (1.6.28-1) ... Selecting previously unselected package libfreetype6:amd64. Preparing to unpack .../04-libfreetype6_2.6.3-3.2_amd64.deb ... Unpacking libfreetype6:amd64 (2.6.3-3.2) ... Selecting previously unselected package libfontconfig1:amd64. Preparing to unpack .../05-libfontconfig1_2.11.0-6.7+b1_amd64.deb ... Unpacking libfontconfig1:amd64 (2.11.0-6.7+b1) ... Selecting previously unselected package libjpeg62-turbo:amd64. Preparing to unpack .../06-libjpeg62-turbo_1%3a1.5.1-2_amd64.deb ... Unpacking libjpeg62-turbo:amd64 (1:1.5.1-2) ... Selecting previously unselected package libjbig0:amd64. Preparing to unpack .../07-libjbig0_2.1-3.1+b2_amd64.deb ... Unpacking libjbig0:amd64 (2.1-3.1+b2) ... Selecting previously unselected package libtiff5:amd64. Preparing to unpack .../08-libtiff5_4.0.8-2+deb9u2_amd64.deb ... Unpacking libtiff5:amd64 (4.0.8-2+deb9u2) ... Selecting previously unselected package libwebp6:amd64. Preparing to unpack .../09-libwebp6_0.5.2-1_amd64.deb ... Unpacking libwebp6:amd64 (0.5.2-1) ... Selecting previously unselected package libxdmcp6:amd64. Preparing to unpack .../10-libxdmcp6_1%3a1.1.2-3_amd64.deb ... Unpacking libxdmcp6:amd64 (1:1.1.2-3) ... Selecting previously unselected package libxcb1:amd64. Preparing to unpack .../11-libxcb1_1.12-1_amd64.deb ... Unpacking libxcb1:amd64 (1.12-1) ... Selecting previously unselected package libx11-data. Preparing to unpack .../12-libx11-data_2%3a1.6.4-3_all.deb ... Unpacking libx11-data (2:1.6.4-3) ... Selecting previously unselected package libx11-6:amd64. Preparing to unpack .../13-libx11-6_2%3a1.6.4-3_amd64.deb ... Unpacking libx11-6:amd64 (2:1.6.4-3) ... Selecting previously unselected package libxpm4:amd64. Preparing to unpack .../14-libxpm4_1%3a3.5.12-1_amd64.deb ... Unpacking libxpm4:amd64 (1:3.5.12-1) ... Selecting previously unselected package libgd3:amd64. Preparing to unpack .../15-libgd3_2.2.4-2+deb9u2_amd64.deb ... Unpacking libgd3:amd64 (2.2.4-2+deb9u2) ... Selecting previously unselected package php7.0-gd. Preparing to unpack .../16-php7.0-gd_7.0.30-0+deb9u1_amd64.deb ... Unpacking php7.0-gd (7.0.30-0+deb9u1) ... Selecting previously unselected package php-gd. Preparing to unpack .../17-php-gd_1%3a7.0+49_all.deb ... Unpacking php-gd (1:7.0+49) ... Setting up libjpeg62-turbo:amd64 (1:1.5.1-2) ... Setting up libpng16-16:amd64 (1.6.28-1) ... Setting up libjbig0:amd64 (2.1-3.1+b2) ... Setting up fonts-dejavu-core (2.37-1) ... Processing triggers for libapache2-mod-php7.0 (7.0.30-0+deb9u1) ... Setting up libtiff5:amd64 (4.0.8-2+deb9u2) ... Processing triggers for sgml-base (1.29) ... Setting up libfreetype6:amd64 (2.6.3-3.2) ... Processing triggers for libc-bin (2.24-11+deb9u3) ... Setting up libxdmcp6:amd64 (1:1.1.2-3) ... Setting up libx11-data (2:1.6.4-3) ... Setting up libxau6:amd64 (1:1.0.8-1) ... Setting up libwebp6:amd64 (0.5.2-1) ... Setting up fontconfig-config (2.11.0-6.7) ... debconf: unable to initialize frontend: Dialog debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.) debconf: falling back to frontend: Readline Setting up libxcb1:amd64 (1.12-1) ... Setting up libfontconfig1:amd64 (2.11.0-6.7+b1) ... Setting up libx11-6:amd64 (2:1.6.4-3) ... Setting up libxpm4:amd64 (1:3.5.12-1) ... Setting up libgd3:amd64 (2.2.4-2+deb9u2) ... Setting up php7.0-gd (7.0.30-0+deb9u1) ... debconf: unable to initialize frontend: Dialog debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.) debconf: falling back to frontend: Readline Creating config file /etc/php/7.0/mods-available/gd.ini with new version Setting up php-gd (1:7.0+49) ... Processing triggers for libc-bin (2.24-11+deb9u3) ... Processing triggers for libapache2-mod-php7.0 (7.0.30-0+deb9u1) ... root@64cbb76c3da3:/# root@64cbb76c3da3:/# root@64cbb76c3da3:/# root@64cbb76c3da3:/# # PHP モジュールを確認 root@64cbb76c3da3:/# php -m [PHP Modules] calendar Core ctype date exif fileinfo filter ftp gd gettext hash iconv json libxml openssl pcntl pcre PDO Phar posix readline Reflection session shmop sockets SPL standard sysvmsg sysvsem sysvshm tokenizer Zend OPcache zlib [Zend Modules] Zend OPcache root@64cbb76c3da3:/#
おわりに
もともと、PHP GD の PHP: getimagesize – Manual が使用したかったのです。
ところが、Docker の php:5.6-apache には入っておりませんでした。
簡単にはインストール出来ませんでしたので、今回の投稿となりました。
次のページが参考になりました、ありがとうございます!
この公式ページで、GD のインストール方法が案内されておりましたので、解決がとても早かったです♪
以上です。