skip to Main Content

I am trying to create my php docker image for my applications, but when I am starting building it, it fails on installing some extensions by showing this error

#0 6.705 (25/26) Installing make (4.3-r0)
#0 6.726 (26/26) Installing re2c (2.1.1-r0)
#0 6.764 Executing busybox-1.34.1-r5.trigger
#0 6.770 OK: 255 MiB in 59 packages
#0 8.461 error: /usr/src/php/ext/libzip does not exist
#0 8.461 
#0 8.461 usage: /usr/local/bin/docker-php-ext-install [-jN] [--ini-name file.ini] ext-name [ext-name ...]
#0 8.461    ie: /usr/local/bin/docker-php-ext-install gd mysqli
#0 8.461        /usr/local/bin/docker-php-ext-install pdo pdo_mysql
#0 8.461        /usr/local/bin/docker-php-ext-install -j5 gd mbstring mysqli pdo pdo_mysql shmop
#0 8.461 
#0 8.461 if custom ./configure arguments are necessary, see docker-php-ext-configure
#0 8.461 
#0 8.461 Possible values for ext-name:
#0 8.496 bcmath bz2 calendar ctype curl dba dom enchant exif ffi fileinfo filter ftp gd gettext gmp hash iconv imap intl json ldap mbstring mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline reflection session shmop simplexml snmp soap sockets sodium spl standard sysvmsg sysvsem sysvshm tidy tokenizer xml xmlreader xmlwriter xsl zend_test zip
#0 8.496 
#0 8.496 Some of the above modules are already compiled into PHP; please check
#0 8.496 the output of "php -i" to see which modules are already loaded.
------
failed to solve: executor failed running [/bin/sh -c apk update && apk add --no-cache --update linux-headers ${PHPIZE_DEPS}     && docker-php-ext-install     exif     mysqli     pdo     pdo_mysql     libzip     freetype    libfreetype6-dev     libjpeg62-turbo-dev     libpng-dev     && docker-php-ext-configure gd --with-freetype --with-jpeg     && docker-php-ext-install -j$(nproc) gd     && docker-php-ext-install opcache]: exit code: 1

The same error is thrown for extensions: zip that I’ve also tried, freetype and libfreetype6-dev. How can I solve these errors? Does it required another extension installed first before these?

For ref this is my dockerfile

FROM php:8.1-fpm-alpine

# Install native PHP extensions
RUN apk update && apk add --no-cache --update linux-headers ${PHPIZE_DEPS} 
    && docker-php-ext-install 
    exif 
    mysqli 
    pdo 
    pdo_mysql 
    libzip 
    freetype
    libfreetype6-dev 
    libjpeg62-turbo-dev 
    libpng-dev 
    && docker-php-ext-configure gd --with-freetype --with-jpeg 
    && docker-php-ext-install -j$(nproc) gd 
    && docker-php-ext-install opcache

2

Answers


  1. Please try the below solution it might help you. Maybe "freetype" required a "GD" library. So we modified the little bit docker file which is below.

    I am referring to this link : Trying to add freetype to php-gd in Docker official image

    FROM php:8.1-fpm-alpine
    
    # Install native PHP extensions
    RUN apk update && apk add --no-cache --update linux-headers ${PHPIZE_DEPS} 
        && apk add --no-cache libzip-dev freetype-dev libjpeg-turbo-dev libpng-dev 
        && docker-php-ext-install 
        exif 
        mysqli 
        pdo 
        pdo_mysql 
        libzip 
        freetype 
        && docker-php-ext-configure gd --with-freetype --with-jpeg 
        && docker-php-ext-install -j$(nproc) gd 
        && docker-php-ext-install opcache

    Hope this will help to you.

    Login or Signup to reply.
  2. There are 2 issues with your solution:

    1. library names, seems they should be libzip-dev, freetype-dev, libjpeg-turbo-dev, libpng-dev
    2. these libs must be installed into the image itself, not as PHP extensions only.

    So, the final Dockerfile that was built successfully is:

    FROM php:8.1-fpm-alpine
    
    # Install native PHP extensions
    RUN apk update 
        && apk add --no-cache --update linux-headers ${PHPIZE_DEPS} 
        && apk add libzip-dev 
           freetype-dev 
           libjpeg-turbo-dev 
           libpng-dev 
        && docker-php-ext-install 
           exif 
           mysqli 
           pdo 
           pdo_mysql 
        && docker-php-ext-configure gd --with-freetype --with-jpeg 
        && docker-php-ext-install -j$(nproc) gd 
        && docker-php-ext-install opcache
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search