Building image php 8.1 + apache - problem with GD is not working

Hi
I’m trying to build an image with PHP 8.1 and Apache + mysqli + GD
I have a problem with GD. Mysqli works but GD doesn’t work.
My sample Dockerfile is below. It is based on Docker
The image builds and runs, but GD does not work.
For example, I have an error
Fatal error: Uncaught Error: Call to undefined function imagecreatetruecolor() in /var/www/html/testgd.php:5 Stack trace: #0 {main} thrown in /var/www/html/testgd.php on line 5

Please give me some tips. Thank you in advance.

FROM php:8.1-apache

RUN docker-php-ext-configure mysqli \
        && docker-php-ext-install -j$(nproc) mysqli

RUN apt-get update && apt-get install -y \
                libfreetype-dev \
                libjpeg62-turbo-dev \
                libpng-dev
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
        && docker-php-ext-install -j$(nproc) gd \
        && docker-php-ext-enable gd

RUN /usr/sbin/a2enmod rewrite

How exactly do did you try the image? I tried the Dockerfile and it just worked fine.

Thank you for checking.
I try for example with such file testgd.php

<?php
var_dump(gd_info());
?>

The result is
Fatal error*: Uncaught Error: Call to undefined function gd_info() in /var/www/html/testgd.php:3 Stack trace: #0 {main} thrown in /var/www/html/testgd.php on line *3

Also when invoking phpinfo() there is no GD information table with options like in case of other modules.
Webmaster also can not operate on images in wordpress.

Please, try this too:

docker run --rm YOURIMAGENAME php -i | grep -i gd

and

docker run --rm YOURIMAGENAME php -m | grep -i gd

Thank you.

docker run --rm php-8.1-apache-ext-gd-zip-pit php -i | grep -i gd
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
gd
GD Support => enabled
GD Version => bundled (2.1.0 compatible)
gd.jpeg_ignore_warning => 1 => 1
GD_ENABLED => true
$_SERVER[‘GD_ENABLED’] => true
$_ENV[‘GD_ENABLED’] => true

docker run --rm php-8.1-apache-ext-gd-zip-pit php -m | grep -i gd
gd

Does it mean that PHP GD is working properly?

Yes it does, at least from command line. If Apache HTTPD can’t use it, it probably loads the configurations from somewhere else and you need to enable GD for HTTPD too. I usually use PHP FPM, so I’m not sure how the Apache variant is built if it is different.

Thank you very much. I understand the problem. I will try to find solution with Apache.