Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing GD extension in Docker

Tags:

php

docker

I'm new to Docker and I'm trying to install PHP GD extension.

This is my current Dockerfile:

FROM php:7.4-fpm-alpine

RUN docker-php-ext-install mysqli pdo pdo_mysql bcmath gd

When running the docker via docker-compose build && docker-compose up -d I'm getting a lots of errors and in the end I get this message:

configure: error: Package requirements (zlib) were not met:

Package 'zlib', required by 'virtual:world', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ZLIB_CFLAGS
and ZLIB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
ERROR: Service 'php' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli pdo pdo_mysql bcmath gd' returned a non-zero code: 1

Without the "gd" at the end the Docker container runs normally.

What could be the problem and how could I fix it?

like image 967
Berisko Avatar asked Apr 15 '20 12:04

Berisko


People also ask

What is the GD extension?

A GD file contains source code written in GDScript, which is a scripting language used to create and modify content in Godot Engine. It stores code in a syntax similar to Python, which may include identifiers, keywords, operators, variables, constants, functions, and comments.

What is Docker PHP ext configure?

docker-php-ext-install - build extension from source, usually executes docker-php-ext-configure for build configuration, enables the extension (php.ini entry) by executing docker-php-ext-enable after all. docker-php-ext-enable - enables an already extension by adding a specific entry to php. ini.

Is it possible to install PHP-GD extension in Docker?

If someone has problems installing php-gd extension in Docker, look up to @Dmitry comment or Documentation and search for "PHP Core Extensions". You can see full code on my Github, if you want to see how am I running my NGINX and PHP with php-gd extension.

How to install GD extension in Apache?

We run the below command to install a gd extension. yum install php-gd. 2. Then, we restart the apache as follows. service httpd restart. That’s it!. Here we have installed the gd library. Similarly, adding GD library support involves executing the command: sudo apt-get install php7.0-gd.

Is your Docker container running normally without the'GD'at the end?

Without the "gd" at the end the Docker container runs normally. What could be the problem and how could I fix it? Show activity on this post.

Is GDGD library extension available with this PHP installation?

GD Library extension not available with this PHP installation. On checking, our Support Engineers found that he was using the Laravel web framework on the CentOS7 server and Nginx web server.


Video Answer


4 Answers

You can try to add these settings in Dockerfile:

FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd

Official documentation. Hope it's help you.

like image 69
Dmitry Avatar answered Nov 03 '22 02:11

Dmitry


In my docker using PHP8.0 I got GD working for jpg,png and webp by adding the following lines to my php.dockerfile:

FROM php:8.0-fpm-alpine

# Install dependencies for GD and install GD with support for jpeg, png webp and freetype
# Info about installing GD in PHP https://www.php.net/manual/en/image.installation.php
RUN apk add --no-cache \
        libjpeg-turbo-dev \
        libpng-dev \
        libwebp-dev \
        freetype-dev

# As of PHP 7.4 we don't need to add --with-png
RUN docker-php-ext-configure gd --with-jpeg --with-webp --with-freetype
RUN docker-php-ext-install gd
like image 20
pe7er Avatar answered Nov 03 '22 03:11

pe7er


One more way to approach the issue is to use install-php-extensions in Dockerfile:

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions gd xdebug

Works in Alpine and PHP8. Docs here

like image 45
FDG Avatar answered Nov 03 '22 03:11

FDG


If someone has problems installing php-gd extension in Docker, look up to @Dmitry comment or Documentation and search for "PHP Core Extensions".

You can see full code on my Github, if you want to see how am I running my NGINX and PHP with php-gd extension.

like image 30
Berisko Avatar answered Nov 03 '22 02:11

Berisko