For a Docker container with PHP 7.4, use these commands to install the extension:
docker-php-ext-configure gd --with-freetype
docker-php-ext-install gd
Using the previous approach results in:
configure: error: unrecognized options: --with-freetype-dir
Relevant comment.