swoole / docker-swoole

🏄 Official Docker Image of Swoole
https://hub.docker.com/r/phpswoole/swoole
Apache License 2.0
526 stars 112 forks source link

phpswoole/swoole:php8.2-dev won't install php extensions via docker-php-ext-install #42

Closed iliavlad closed 1 year ago

iliavlad commented 1 year ago

Dockerfile to test

FROM phpswoole/swoole:php8.2-dev

RUN docker-php-ext-install pcntl

and run

docker build -t testphpswoole .

expected result (as for phpswoole/swoole image)

STEP 2/2: RUN     docker-php-ext-install pcntl
Configuring for:
PHP Api Version:         20210902
Zend Module Api No:      20210902
Zend Extension Api No:   420210902
# more logs
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20210902/
# ...
COMMIT testphpswoole
--> Pushing cache
# ...

actual result

STEP 2/2: RUN     docker-php-ext-install pcntl
Configuring for:
PHP Api Version:         20220829
Zend Module Api No:      20220829
Zend Extension Api No:   420220829
# ...
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20220829/
/usr/local/bin/docker-php-ext-enable: 5: cd: can't cd to [2023-07-11 05:24:22 @2052.0]  TRACE   Context::Context(:53): alloc stack: size=2097152, ptr=0x7ffa01001010
/usr/local/lib/php/extensions/no-debug-non-zts-20220829
Error: building at STEP "RUN docker-php-ext-install pcntl": while running runtime: exit status 123

A reason is an additional log in script https://github.com/docker-library/php/blob/6cb0a331566b66ae30c14884cc93cd2b3218d324/docker-php-ext-enable#L4

May be it's possible to advise how to install php extension to dev image of phpswoole

deminy commented 1 year ago

Hi there. The DEV image is for debugging purpose and it's not expected to be used in that way.

Here is an example to properly install the pcntl extension in the Swoole image:

FROM phpswoole/swoole:php8.2

RUN set -ex && \
    docker-php-ext-configure pcntl --enable-pcntl && \
    docker-php-ext-install pcntl

We can test the Dockerfile with the following commands:

docker build -t testphpswoole-1 . # To build the image.

docker run --rm -ti testphpswoole-1 php -m | grep pcntl # To check if the pcntl extension is loaded or not.
docker run --rm -ti testphpswoole-1 php --ri pcntl # To check configurations of the pcntl extension.

However, in case we do want to install the pcntl extension in the DEV image, we can do it with multi-stage builds:

FROM phpswoole/swoole:php8.2

RUN set -ex && \
    docker-php-ext-configure pcntl --enable-pcntl && \
    docker-php-ext-install pcntl

FROM phpswoole/swoole:php8.2-dev

COPY --from=0 /usr/local/lib/php/extensions/no-debug-non-zts-20220829/pcntl.so /usr/local/lib/php/extensions/no-debug-non-zts-20220829/pcntl.so
COPY --from=0 /usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini /usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini

Now, we can test the Dockerfile with the following commands:

docker build -t testphpswoole-2 . # To build the image.

docker run --rm -ti testphpswoole-2 php -m | grep pcntl # To check if the pcntl extension is loaded or not.
docker run --rm -ti testphpswoole-2 php --ri pcntl # To check configurations of the pcntl extension.