sajad torkamani

In a nutshell

Before installing an extension, check if it’s already installed in your Docker image. Start an interactive bash session in your container and run php -m | grep <extension>. For example:

php -m | grep gd

Once you’ve checked it’s not already installed, you can do something like this:

FROM php:7.4-fpm

RUN apt-get update && apt-get install -y \
		libfreetype6-dev \
		libjpeg62-turbo-dev \
		libpng-dev \
	&& docker-php-ext-configure gd --with-freetype --with-jpeg \
	&& docker-php-ext-install -j$(nproc) gd

The steps are:

  1. Install system dependencies (e.g., Ubuntu APT packages)
  2. If needed, use docker-php-ext-configure to configure the extension prior to installation.
  3. Use docker-php-ext-install to install the extension.

Make things easier with docker-php-extension-installer

You can also use the docker-php-extension-installer project to ease this process. You get ainstall-php-extensions script that takes care of automatically adding and removing Debian (APT) and Alpine (APK) packages for you. For example, to install the gd extensions, you can run:

install-php-extensions gd

Sources

Leave a comment

Your email address will not be published. Required fields are marked *