6

I am using the official php:fpm docker image as base for my application container, so the Dockerfile starts like so:

FROM php:fpm

Later in the file I would like to have something like that:

RUN apt-get install -y \
    php7.0-gd

But that tells me:

E: Unable to locate package php7.0-gd
E: Couldn't find any package by regex 'php7.0-gd'

»Bashing« into the container using docker exec -it <name> /bin/bash and executing: apt-cache search php | grep gd yields:

php5-gdcm - Grassroots DICOM PHP5 bindings
php5-vtkgdcm - Grassroots DICOM VTK PHP bindings
php5-gd - GD module for php5

So since that is a debian (yessie) based image, only the old php5 packages are available and php7 is installed by some tricky script in the php:fpm dockerfile and it seams that all extensions are compiled within the used php executable.

How can I install more extensions in this scenario?

3
  • 1
    You likely need to do an apt-get update first. Also note that there are instructions for this at hub.docker.com/_/php and they provide the helper scripts docker-php-ext-configure, docker-php-ext-install, and docker-php-ext-enable to more easily install PHP extensions. Commented Oct 18, 2017 at 8:44
  • The update is done before those line… Commented Oct 18, 2017 at 8:49
  • Have you tried the code snippet given in the section titled "PHP Core Extensions"? Commented Oct 18, 2017 at 8:49

1 Answer 1

13

Quoting https://hub.docker.com/_/php/

How to install more PHP extensions

We provide the helper scripts docker-php-ext-configure, docker-php-ext-install, and docker-php-ext-enable to more easily install PHP extensions.

To install PHP with iconv, mcrypt and GD, they provide the following example:

FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

Please refer to the Dockerhub page for more details.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, Seams that I missed to read the whole page ;) Thanks for that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.