bitnami/bitnami-docker-php-fpm

Recommended way to install an extension that is not in your default list

dominikkrulak opened this issue · 1 comments

It relates a little to the issue Feature request: easier installation of ImageMagick PHP extension.

Let's say I'd like to add redis extension.

I'm browsing files folder downloaded from link in the Dockerfile and I could locate in files/php/bin/pecl executable file.
So I don't need to build another layer by installing PECL again.

To install redis extension using PECL I need to run pecl install redis.

I'm quiet reproducing what I used to do with previous versions of bitnami docker php-fpm image (currenlty 7.4.3).

FROM bitnami/php-fpm:8.1.0-debian-10-r3 AS builder
FROM docker.io/bitnami/minideb:buster
LABEL maintainer "Bitnami <containers@bitnami.com>"

ENV OS_ARCH="amd64" \
    OS_FLAVOUR="debian-10" \
    OS_NAME="linux"

COPY prebuildfs /
# Install required system packages and dependencies
RUN install_packages ca-certificates curl gzip autoconf libbsd0 libbz2-1.0 libc6 libcom-err2 libcurl4 libexpat1 libffi6 libfftw3-double3 libfontconfig1 libfreetype6 libgcc1 libgcrypt20 libglib2.0-0 libgmp10 libgnutls30 libgomp1 libgpg-error0 libgssapi-krb5-2 libhogweed4 libicu63 libidn2-0 libjpeg62-turbo libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 liblcms2-2 libldap-2.4-2 liblqr-1-0 libltdl7 liblzma5 libmagickcore-6.q16-6 libmagickwand-6.q16-6 libmemcached11 libmemcachedutil2 libncurses6 libnettle6 libnghttp2-14 libonig5 libp11-kit0 libpcre3 libpng16-16 libpq5 libpsl5 libreadline7 librtmp1 libsasl2-2 libsodium23 libsqlite3-0 libssh2-1 libssl1.1 libstdc++6 libsybdb5 libtasn1-6 libtidy5deb1 libtinfo6 libunistring2 libuuid1 libwebp6 libx11-6 libxau6 libxcb1 libxdmcp6 libxext6 libxml2 libxslt1.1 libzip4 procps tar wget zlib1g

COPY --from=builder /opt/bitnami/common /opt/bitnami/common
COPY --from=builder /opt/bitnami/php /opt/bitnami/php

RUN /opt/bitnami/php/bin/pecl install redis

I copy the snippet of a problem from my terminal.

------                                                                                                                  
 > [stage-1 6/7] RUN /opt/bitnami/php/bin/pecl install redis:                                                           
#12 1.994 WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update   
#12 2.606 downloading redis-5.3.4.tgz ...                                                                               
#12 2.606 Starting to download redis-5.3.4.tgz (268,154 bytes)                                                          
#12 2.742 ........................................................done: 268,154 bytes                                   
#12 3.664 29 source files, building
#12 3.665 running: phpize
#12 3.681 Configuring for:
#12 3.681 PHP Api Version:         20210902
#12 3.681 Zend Module Api No:      20210902
#12 3.681 Zend Extension Api No:   420210902
#12 4.912 enable igbinary serializer support? [no] : enable lzf compression support? [no] : enable zstd compression support? [no] : building in /tmp/pear/temp/pear-build-defaultuserfVJdpp/redis-5.3.4
#12 4.915 running: /tmp/pear/temp/redis/configure --with-php-config=/opt/bitnami/php/bin/php-config --enable-redis-igbinary=no --enable-redis-lzf=no --enable-redis-zstd=no
#12 5.154 checking for grep that handles long lines and -e... /bin/grep
#12 5.159 checking for egrep... /bin/grep -E
#12 5.167 checking for a sed that does not truncate output... /bin/sed
#12 5.199 checking for pkg-config... no
#12 5.200 checking for cc... no
#12 5.207 checking for gcc... no
#12 5.207 configure: error: in `/tmp/pear/temp/pear-build-defaultuserfVJdpp/redis-5.3.4':
#12 5.207 configure: error: no acceptable C compiler found in $PATH
#12 5.207 See `config.log' for more details
#12 5.249 ERROR: `/tmp/pear/temp/redis/configure --with-php-config=/opt/bitnami/php/bin/php-config --enable-redis-igbinary=no --enable-redis-lzf=no --enable-redis-zstd=no' failed
------

Seems like pkg-config, cc, gcc are problem.

Anyway, I'm not sure if this is a good way build image with extension that is not in your "default" list.
Or maybe is. Or maybe I'm tired of this and not paying attention to :\

Sometimes you don't need that many extensions to be running in your system therefore you'd get bigger build size.
It smells for a solution to effectively "add" and "remove" extensions to and from image.
Something like to run shell script with flags representing extensions that you'd like to install along.
I don't know...

Hi @dominikkrulak

Please we don't include the build deps in "final" images. We only include the runtime dependencies to execute PHP-FPM + the default included extensions.

To customize the image to include custom extensions, you might need to install system packages such as build-essentials to build them. We highly recommend using multi-stage builds for that so you define a stage to build your extensions, and a different one with only the runtime deps + the assets you built to create your final image.