PHP / DOCKER / GD Lib - Error: unrecognized options: --with-png-dir, --with-jpeg-dir, --with-freetype-dir


My issue:

I'm trying to create a docker container with php: 7.4.1-apache, but I'm getting the following error when running: docker-compose build

configure: error: unrecognized options: --with-png-dir, --with-jpeg-dir, --with-freetype-dir
ERROR: Service 'php' failed to build: The command '/bin/sh -c docker-php-ext-configure gd   --with-png-dir=/usr/include/   --with-jpeg-dir=/usr/include/   --with-freetype-dir=/usr/include/' returned a non-zero code: 1

This is the part in my docker file which causes the error:

RUN docker-php-ext-configure gd \
  --with-png-dir=/usr/include/ \
  --with-jpeg-dir=/usr/include/ \

How to solve this issue with Docker and PHP. I need the GD lib working for my software project.

Software Question created: 2021-03-27 13:41 HungaryBoy


The flags have changed due to massiv update in the GD lib itself. The --with-png flag have been removed but png is supported by default. You don't need that flag anymore.


Use this docker-php-ext-configure flags to make it work for PHP 7.4, PHP 8.0 and PHP 8.1 and all other new versions of PHP.

RUN docker-php-ext-configure gd --with-freetype --with-jpeg

For PHP <7.3 and older version you need to use this flags:

RUN docker-php-ext-configure gd
answered 2021-12-27 13:49 zulu