Problems installing GD on php7.2 with docker (Docker version 18.09.7, build 2d0083d)

configure: error: jpeglib.h not found
sometmes its png.h not found

driving me absolutely crazy. I have followed every stackoverflow article I have been able to find on google to no avail.

can someone please take a look?

here is my compose file

version: ‘3’
services:
php-apache:
image: php:7.2.1-apache
ports:
- 80:80
volumes:
- ./DocumentRoot:/var/www/html:z
links:
- ‘mariadb’
command: docker-php-ext-install mysqli pdo pdo_mysql
command: apt-get update --fix-missing && apt-get install -y
curl
build-essential
libssl-dev
libfreetype6-dev
nano
libxpm-dev
libjpeg62-turbo-dev
libpng-dev
libmcrypt-dev
libicu-dev
libxml2-dev
libwebp-dev
command: docker-php-ext-install -j$(nproc) iconv
command: docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/

mariadb:
image: mariadb:10.1
ports:
- 3306:3306
volumes:
- mariadb:/var/lib/mysql
environment:
TZ: “Europe/Rome”
MYSQL_ALLOW_EMPTY_PASSWORD: “no”
MYSQL_ROOT_PASSWORD: “blah”
MYSQL_USER: ‘testuser’
MYSQL_PASSWORD: ‘blah’
MYSQL_DATABASE: ‘testdb’

volumes:
mariadb:

Hi

You cant have multiple commands, atleast not like this.
The best thing you can do is to build and image where this is installed (will also speed up deployment time)

according to: https://hub.docker.com/_/php

PHP Core Extensions

For example, if you want to have a PHP-FPM image with iconv and gd extensions, you can inherit the base image that you like, and write your own Dockerfile like this:

FROM php:7.2-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd
2 Likes

Works like a charm. I feel my understanding of docker base images has improved so do feel a little sheepish for the original post, so thank you for your patient and informative response. :slight_smile:

1 Like

This helps me a lot and very appreciated.