I don’t understand how to install gd2 library with Docker on linux mint.
This is my docker-compose file
version: '3'
services:
web:
build: ./web
environment:
- APACHE_RUN_USER=#1000
volumes:
- ${APP_PATH_HOST}:${APP_PATH_CONTAINER}
- ./web/php.ini:/usr/local/etc/php/php.ini
ports:
- 8080:80
working_dir: ${APP_PATH_CONTAINER}
db:
image: mariadb
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: 12345
MYSQL_DATABASE: books
MYSQL_USER: root
MYSQL_PASSWORD: 12345
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ${DB_PATH_HOST}:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 6080:8080
composer:
image: composer:1.6
volumes:
- ${APP_PATH_HOST}:${APP_PATH_CONTAINER}
working_dir: ${APP_PATH_CONTAINER}
command: composer install
After I do docker-compose up --build
and I have no errors during the building, but when I do docker exec -it books_web_1 bash
and check php version php -v
, I get this error
PHP Warning: PHP Startup: Unable to load dynamic library 'gd2' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/gd2 (/usr/local/lib/php/extensions/no-debug-non-zts-20190902/gd2: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/gd2.so (/usr/local/lib/php/extensions/no-debug-non-zts-20190902/gd2.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Dockerfile for ‘web’ container
FROM php:7.4-apache
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
libmcrypt-dev
libfreetype6-dev
libjpeg62-turbo-dev
libpng-dev
libpq-dev
zlib1g-dev
&& docker-php-ext-install -j$(nproc) iconv
&& docker-php-ext-configure gd
&& docker-php-ext-install -j$(nproc) gd
&& docker-php-ext-install
pdo
pdo_mysql
pgsql
bcmath
gd
&& a2enmod
rewrite
RUN rm -rf /var/lib/apt/lists/*
So what else do i need for install gd2?
3
Answers
I couldn’t reproduce your issue using your Dockerfile, however I had similar issue trying to build my PHP image on Ubuntu rather than on Debian but using https://github.com/docker-library/drupal/blob/4e4d23ee86e88a0e6e88ec28837402ad1c8453fa/9.0/fpm-buster/Dockerfile as example of adding additional PHP extensions.
In my images, when I tried to check loaded modules (php -m) I got:
In that file line 41 you will see:
which I replaced with
and now modules are loading correctly.
I’m not an expert in shared libraries and linking, but it is fixing the paths to libs so there is no more problems.
For me the fix was to edit the
php.ini
file by changingextension=gd2
toextension=gd
I am using
php:7.4-apache
like the asker.This issue can also be caused by …
extension_dir
entry in yourphp.ini
,php.ini
file