LoginSignup
6
5

More than 1 year has passed since last update.

PHP 7.4 と xdebug 3.2 だとバージョンの不一致で Docker の build がうまくいかない。

Last updated at Posted at 2023-04-13

1. 現状確認

1-1. やりたいこと

過去作成した以下の個人開発アプリのDockerイメージをビルドして、Dockerコンテナを生成、起動したい。

1-2.エラー内容

以下の docker コマンドを実行したところ、エラーが発生して、ビルドできない。

docker compose build
#0 242.0 creating bcmath.la
#0 242.0 (cd .libs && rm -f bcmath.la && ln -s ../bcmath.la bcmath.la)
#0 242.0 /bin/bash /usr/src/php/ext/bcmath/libtool --mode=install cp ./bcmath.la /usr/src/php/ext/bcmath/modules
#0 242.1 cp ./.libs/bcmath.so /usr/src/php/ext/bcmath/modules/bcmath.so
#0 242.1 cp ./.libs/bcmath.lai /usr/src/php/ext/bcmath/modules/bcmath.la
#0 242.2 PATH="$PATH:/sbin" ldconfig -n /usr/src/php/ext/bcmath/modules
#0 242.2 ----------------------------------------------------------------------
#0 242.2 Libraries have been installed in:
#0 242.2    /usr/src/php/ext/bcmath/modules
#0 242.2 
#0 242.2 If you ever happen to want to link against installed libraries
#0 242.2 in a given directory, LIBDIR, you must either use libtool, and
#0 242.2 specify the full pathname of the library, or use the `-LLIBDIR'
#0 242.2 flag during linking and do at least one of the following:
#0 242.2    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
#0 242.2      during execution
#0 242.2    - add LIBDIR to the `LD_RUN_PATH' environment variable
#0 242.2      during linking
#0 242.2    - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
#0 242.2    - have your system administrator add LIBDIR to `/etc/ld.so.conf'
#0 242.2 
#0 242.2 See any operating system documentation about shared libraries for
#0 242.2 more information, such as the ld(1) and ld.so(8) manual pages.
#0 242.2 ----------------------------------------------------------------------
#0 242.2 
#0 242.2 Build complete.
#0 242.2 Don't forget to run 'make test'.
#0 242.2 
#0 242.2 + strip --strip-all modules/bcmath.so
#0 242.2 Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20190902/
#0 242.4 find . -name \*.gcno -o -name \*.gcda | xargs rm -f
#0 242.4 find . -name \*.lo -o -name \*.o | xargs rm -f
#0 242.4 find . -name \*.la -o -name \*.a | xargs rm -f
#0 242.4 find . -name \*.so | xargs rm -f
#0 242.4 find . -name .libs -a -type d|xargs rm -rf
#0 242.4 rm -f libphp.la      modules/* libs/*
#0 244.4 + composer config -g process-timeout 3600
#0 244.8 + composer config -g repos.packagist composer https://packagist.org
#0 244.9 + pecl install xdebug
#0 250.7 pecl/xdebug requires PHP (version >= 8.0.0, version <= 8.2.99), installed version is 7.4.33
#0 250.7 No valid packages found
#0 250.7 install failed
------
failed to solve: executor failed running [/bin/bash -oeux pipefail -c apt-get update &&     apt-get -y install git libicu-dev libonig-dev libzip-dev unzip locales &&     apt-get clean &&     rm -rf /var/lib/apt/lists/* &&     locale-gen en_US.UTF-8 &&     localedef -f UTF-8 -i en_US en_US.UTF-8 &&     mkdir /var/run/php-fpm &&     docker-php-ext-install intl pdo_mysql zip bcmath &&     composer config -g process-timeout 3600 &&     composer config -g repos.packagist composer https://packagist.org &&     pecl install xdebug &&     docker-php-ext-enable xdebug]: exit code: 1

以下の行で、

#0 250.7 pecl/xdebug requires PHP (version >= 8.0.0, version <= 8.2.99), installed version is 7.4.33

xdebugのバージョンに対して、PHPのバージョンが一致してないよ、と言われている様子。

2. 調査

ChatGPT(GPT-4)に聞いてみた。以下回答。

Dockerのビルドが失敗している原因は、PHPのバージョンとxdebugの要求するバージョンが一致しないためです。

エラーメッセージを見ると、「pecl/xdebug requires PHP (version >= 8.0.0, version <= 8.2.99), installed version is 7.4.33」とあります。つまり、インストールされているPHPのバージョンが7.4.33で、xdebugが必要とするPHPのバージョンは8.0.0以上8.2.99以下です。

この問題を解決するには、以下のいずれかの方法を試してみてください。

  1. PHPのバージョンをアップデートする: PHP 8.0.0以上にアップデートすることで、xdebugとの互換性が解決されます。Dockerfile内で使用しているPHPのイメージを変更してください。例えば、 php:8.0-fpmphp:8.1-fpm を使用してみてください。
  2. 互換性のあるxdebugのバージョンをインストールする: インストールしようとしているxdebugのバージョンが、インストールされているPHP 7.4.33と互換性がない場合、互換性のあるxdebugのバージョンをインストールする必要があります。以下のようにして、特定のバージョンのxdebugをインストールしてみてください。
pecl install xdebug-2.9.8

注意: 上記の例では、xdebug 2.9.8をインストールしていますが、これは例であり、実際の状況に応じて適切なバージョンを選択する必要があります。 xdebugのリリースページ で互換性のあるバージョンを確認できます。

いずれかの方法で問題が解決しない場合は、Dockerfileやビルドスクリプトを確認して、他にも問題がないかをチェックしてください。

原因はPHPのバージョンとxdebugの要求するバージョンが一致しないためで間違いなさそうなので、バージョンの互換性を確認する。

infra/docker/php/Dockerfile
FROM php:7.4-fpm-buster
LABEL maintainer="ucan-lab <yes@u-can.pro>"
SHELL ["/bin/bash", "-oeux", "pipefail", "-c"]

# timezone environment
ENV TZ=UTC \
    # locale
    LANG=en_US.UTF-8 \
    LANGUAGE=en_US:en \
    LC_ALL=en_US.UTF-8 \
    # composer environment
    COMPOSER_ALLOW_SUPERUSER=1 \
    COMPOSER_HOME=/composer

COPY --from=composer:2.0 /usr/bin/composer /usr/bin/composer

RUN apt-get update && \
    apt-get -y install git libicu-dev libonig-dev libzip-dev unzip locales && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    locale-gen en_US.UTF-8 && \
    localedef -f UTF-8 -i en_US en_US.UTF-8 && \
    mkdir /var/run/php-fpm && \
    docker-php-ext-install intl pdo_mysql zip bcmath && \
    composer config -g process-timeout 3600 && \
    composer config -g repos.packagist composer https://packagist.org && \
    pecl install xdebug && \
    docker-php-ext-enable xdebug

COPY ./infra/docker/php/php-fpm.d/zzz-www.conf /usr/local/etc/php-fpm.d/zzz-www.conf
COPY ./infra/docker/php/php.ini /usr/local/etc/php/php.ini
COPY ./infra/docker/php/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

WORKDIR /work/backend

pecl install xdebug と記述しており、バージョンを指定していないため、Xdebug バージョン 3.2(最新バージョン)をインストールしてしまっている。

image.png

3.1系の最終バージョンは3.1.6

3. 試行

バージョンを指定する。

infra/docker/php/Dockerfile
FROM php:7.4-fpm-buster
LABEL maintainer="ucan-lab <yes@u-can.pro>"
SHELL ["/bin/bash", "-oeux", "pipefail", "-c"]

# timezone environment
ENV TZ=UTC \
    # locale
    LANG=en_US.UTF-8 \
    LANGUAGE=en_US:en \
    LC_ALL=en_US.UTF-8 \
    # composer environment
    COMPOSER_ALLOW_SUPERUSER=1 \
    COMPOSER_HOME=/composer

COPY --from=composer:2.0 /usr/bin/composer /usr/bin/composer

RUN apt-get update && \
    apt-get -y install git libicu-dev libonig-dev libzip-dev unzip locales && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    locale-gen en_US.UTF-8 && \
    localedef -f UTF-8 -i en_US en_US.UTF-8 && \
    mkdir /var/run/php-fpm && \
    docker-php-ext-install intl pdo_mysql zip bcmath && \
    composer config -g process-timeout 3600 && \
    composer config -g repos.packagist composer https://packagist.org && \
-    pecl install xdebug && \
+    pecl install xdebug-3.1.6 && \
    docker-php-ext-enable xdebug

COPY ./infra/docker/php/php-fpm.d/zzz-www.conf /usr/local/etc/php-fpm.d/zzz-www.conf
COPY ./infra/docker/php/php.ini /usr/local/etc/php/php.ini
COPY ./infra/docker/php/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

WORKDIR /work/backend

以下の docker コマンドを実行する。

docker compose build
# r_yamate @ mbp in ~/development/yonde-web-app on git:main o [21:51:23] C:17
$ docker compose build
[+] Building 0.0s (0/0)                                                                                                                 
[+] Building 0.0s (0/0)                                                                                                                 
[+] Building 0.2s (0/2)                                                                                                                 
 => [internal] load build definition from Dockerfile                                                                               0.2s
[+] Building 0.1s (0/1)                                                                                                                 
 => [internal] load build definition from Dockerfile                                                                               0.1s
[+] Building 0.4s (1/2)                                                                                                                 
 => [internal] load build definition from Dockerfile                                                                               0.4s
[+] Building 0.4s (1/2)                                                                                                                 
 => [internal] load build definition from Dockerfile                                                                               0.4s
[+] Building 0.6s (2/3)                                                                                                                 
[+] Building 0.9s (2/4)                                                                                                                 
 => => exporting layers                                                                                                            0.0s 
 => => writing image sha256:ea9fc494071c32c6e62097bd76197fc661217fdc26cccd7104df43d28d62eb67                                       0.0s 
 => => naming to docker.io/library/yonde-web-app-db                                                                                0.0s
 => [internal] load build definition from Dockerfile                                                                               0.5s 
[+] Building 8.6s (5/12)                                                                                                                
 => [internal] load build definition from Dockerfile                                                                               0.5s 
 => => transferring dockerfile: 1.19kB                                                                                             0.4s
 => => transferring dockerfile: 540B                                                                                               0.5s 
 => [internal] load .dockerignore                                                                                                  0.0s
[+] Building 9.1s (5/12)                                                                                                                
 => [internal] load build definition from Dockerfile                                                                               0.5s 
 => => transferring dockerfile: 1.19kB                                                                                             0.4s
[+] Building 9.6s (6/13)                                                                                                                
[+] Building 9.5s (13/13) FINISHED                                                                                                      
 => [internal] load build definition from Dockerfile                                                                               0.5s
 => => transferring dockerfile: 1.19kB                                                                                             0.4s
 => [internal] load .dockerignore                                                                                                  0.0s
 => => transferring context: 2B                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/php:7.4-fpm-buster                                                              5.3s
 => FROM docker.io/library/composer:2.0                                                                                            3.3s
 => => resolve docker.io/library/composer:2.0                                                                                      3.3s
 => [internal] load build context                                                                                                  0.0s
 => => transferring context: 290B                                                                                                  0.0s
[+] Building 12.1s (14/14) FINISHED                                                                                                     
 => [internal] load build definition from Dockerfile                                                                               0.5s
 => => transferring dockerfile: 540B                                                                                               0.5s
 => [internal] load .dockerignore                                                                                                  0.0s
 => => transferring context: 2B                                                                                                    0.0s
 => [internal] load metadata for docker.io/library/node:14.2-alpine                                                                8.7s
 => [internal] load metadata for docker.io/library/nginx:1.18-alpine                                                               7.2s
 => [node 1/1] FROM docker.io/library/node:14.2-alpine@sha256:6de416f8c664eb6b0a28905389ecbea7ccec0d9e0651da8662ccd2e566b7cbf7     0.0s
 => [internal] load build context                                                                                                  2.8s
 => => transferring context: 1.02kB                                                                                                2.8s
 => [stage-1 1/7] FROM docker.io/library/nginx:1.18-alpine@sha256:93baf2ec1bfefd04d29eb070900dd5d79b0f79863653453397e55a5b663a6cb  0.0s
 => CACHED [stage-1 2/7] RUN apk update &&   apk add --update --no-cache --virtual=.build-dependencies g++                         0.0s
 => CACHED [stage-1 3/7] COPY --from=node /usr/local/bin /usr/local/bin                                                            0.0s
 => CACHED [stage-1 4/7] COPY --from=node /usr/local/lib /usr/local/lib                                                            0.0s
 => CACHED [stage-1 5/7] COPY --from=node /opt /opt                                                                                0.0s
 => CACHED [stage-1 6/7] COPY ./infra/docker/nginx/*.conf /etc/nginx/conf.d/                                                       0.0s
 => CACHED [stage-1 7/7] WORKDIR /work/backend                                                                                     0.0s
 => exporting to image                                                                                                             0.0s
 => => exporting layers                                                                                                            0.0s
 => => writing image sha256:117a1dd176deef7ff0d946fa31e1a2cb26ea2fcb98c16d71146fb5f909a9149b                                       0.0s
 => => naming to docker.io/library/yonde-web-app-web                                                                               0.0s

# r_yamate @ mbp in ~/development/yonde-web-app on git:main x [22:02:05] 
$ docker compose up -d
[+] Running 6/6
 ⠿ Network yonde-web-app_default         Created                                                                                   0.4s
 ⠿ Container yonde-web-app-db-1          Started                                                                                  14.9s
 ⠿ Container yonde-web-app-app-1         Started                                                                                  15.2s
 ⠿ Container yonde-web-app-mail-1        Started                                                                                  15.2s
 ⠿ Container yonde-web-app-web-1         Started                                                                                  14.9s
 ⠿ Container yonde-web-app-phpmyadmin-1  Started                                                                                  15.7s

# r_yamate @ mbp in ~/development/yonde-web-app on git:main x [22:02:27] 
$ docker compose ps   
NAME                         IMAGE                   COMMAND                  SERVICE             CREATED              STATUS                    PORTS
yonde-web-app-app-1          yonde-web-app-app       "docker-php-entrypoi…"   app                 About a minute ago   Up 57 seconds             9000/tcp
yonde-web-app-db-1           yonde-web-app-db        "/entrypoint.sh mysq…"   db                  About a minute ago   Up 57 seconds (healthy)   0.0.0.0:3306->3306/tcp, 33060-33061/tcp
yonde-web-app-mail-1         mailhog/mailhog         "MailHog"                mail                About a minute ago   Up 56 seconds             1025/tcp, 0.0.0.0:8025->8025/tcp
yonde-web-app-phpmyadmin-1   phpmyadmin/phpmyadmin   "/docker-entrypoint.…"   phpmyadmin          About a minute ago   Up 55 seconds             0.0.0.0:40080->80/tcp
yonde-web-app-web-1          yonde-web-app-web       "/docker-entrypoint.…"   web                 About a minute ago   Up 57 seconds             0.0.0.0:80->80/tcp

解決!

バージョン大事。

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5