I am a complete Docker novice but am having to maintain an existing system. The Dockerfile I am using is as below:
FROM php:5.6-apache
RUN docker-php-ext-in
It is not the case of the OP, but I found that for those that are using php:7.4-fpm-alpine the syntax is a bit different
FROM php:7.4-fpm-alpine
# ... Other instructions ...
# Setup GD extension
RUN apk add --no-cache \
freetype \
libjpeg-turbo \
libpng \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd \
--with-freetype=/usr/include/ \
# --with-png=/usr/include/ \ # No longer necessary as of 7.4; https://github.com/docker-library/php/pull/910#issuecomment-559383597
--with-jpeg=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-enable gd \
&& apk del --no-cache \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
&& rm -rf /tmp/*
# ... Other instructions ...