Docker - Unable to load dynamic library 'gd2'
Asked Answered
M

3

5

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?

Meridith answered 7/3, 2020 at 8:17 Comment(0)
S
8

For me the fix was to edit the php.ini file by changing extension=gd2 to extension=gd

I am using php:7.4-apache like the asker.

Submergible answered 4/9, 2020 at 7:39 Comment(2)
This definitely solved 40 minutes frustrating googling and trial and error!Dynamiter
Nope, "Build": PHP Warning: PHP Startup: Unable to load dynamic library 'gd'Pallaten
L
1

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:

PHP Warning:  PHP Startup: Unable to load dynamic library 'gd.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/gd.so (libpng16.so.16: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/gd.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20190902/gd.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning:  PHP Startup: Unable to load dynamic library 'zip.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/zip.so (libzip.so.5: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20190902/zip.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20190902/zip.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

In that file line 41 you will see:

| xargs -r dpkg-query -S \

which I replaced with

| xargs -r realpath | xargs -r dpkg-query --search \

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.

Lamberto answered 13/8, 2020 at 5:15 Comment(0)
C
1

This issue can also be caused by ...

  • an invalid extension_dir entry in your php.ini,
  • a conflicting php.ini file
  • or an invalid extension name.
Clarettaclarette answered 6/9, 2021 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.