如何在 Docker 的官方 php-fpm-alpine 映像上安装 XDebug?

2022-08-30 13:13:03

我正在使用基于(https://github.com/docker-library/wordpress/blob/master/php7.1/fpm-alpine/Dockerfile)。wordpress:php7.1-fpm-alpinephp:7.1-fpm-alpine

我试过了RUN pecl install xdebug-2.5.0 && docker-php-ext-enable xdebug

这会导致在构建时出错:

Step 19/19 : RUN pecl install xdebug-2.5.0     && docker-php-ext-enable xdebug
 ---> Running in 52c988e12cb2
downloading xdebug-2.5.0.tgz ...
Starting to download xdebug-2.5.0.tgz (267,640 bytes)
........................................................done: 267,640 bytes
76 source files, building
running: phpize
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

答案 1

以下内容足以简单地在该映像上安装 xdebug:

FROM wordpress:php7.1-fpm-alpine

RUN apk add --no-cache $PHPIZE_DEPS \
    && pecl install xdebug-2.5.0 \
    && docker-php-ext-enable xdebug

构建它,然后在生成的映像内从 shell 运行,将生成以下内容:

$ php -i | grep Xdebug
    with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans

答案 2

如果您担心映像大小,可以删除依赖项:

FROM wordpress:php7.1-fpm-alpine 
RUN apk --update --no-cache add autoconf g++ make && \
    pecl install -f xdebug && \
    docker-php-ext-enable xdebug && \
    apk del --purge autoconf g++ make

推荐