Evgeny Musonov
Evgeny Musonov

Reputation: 331

Docker - Unable to load dynamic library 'gd2'

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?

Upvotes: 5

Views: 6739

Answers (3)

Phidelux
Phidelux

Reputation: 2271

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.

Upvotes: 1

brandon musa
brandon musa

Reputation: 151

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.

Upvotes: 8

Kirill Roskolii
Kirill Roskolii

Reputation: 101

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.

Upvotes: 1

Related Questions