First, we need to update our apt sources.list
/etc/apt/sources.list
deb http://archive.debian.org/debian-security stretch/updates main contrib non-free
Then run this command
apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev && docker-php-ext-configure gd --with-freetype-dir=/usr/include/freetype2 --with-png-dir=/usr/include --with-jpeg-dir=/usr/include && docker-php-ext-install gd