0

I try to install GD, because I'm getting the error "Call to undefined function imagecreatefromjpeg()".

When building the image I'm getting the error

E: Unable to locate package libfreetype6-dev
E: Unable to locate package libjpeg62-turbo-dev
E: Unable to locate package libpng12-dev
The command '/bin/sh -c apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng12-dev && docker-php-ext-configure gd --enable-gd-native-ttf --with-freetype-dir=/usr/include/freetype2 --with-png-dir=/usr/include --with-jpeg-dir=/usr/include && docker-php-ext-install gd && docker-php-ext-enable gd' returned a non-zero code: 100

My Dockerfile

FROM php:7-fpm

# Install GD
RUN apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng12-dev \
&& docker-php-ext-configure gd \
--enable-gd-native-ttf \
--with-freetype-dir=/usr/include/freetype2 \
--with-png-dir=/usr/include \
--with-jpeg-dir=/usr/include \
&& docker-php-ext-install gd \
&& docker-php-ext-enable gd

What's the right way to install GD?

Dennis
  • 27
  • 2
  • 7

2 Answers2

0

What about running apt-get update first to update local list of packages? It should always be run before installing:

FROM php:7-fpm
RUN apt-get update && apt-get install --yes libfreetype6-dev ....
grapes
  • 8,185
  • 1
  • 19
  • 31
  • Ok, I've updated my Dockerfile. I'm a newbie to Docker, what to run now? I'm using a docker-compose.yml. docker-compose up -d seems not to update the image.. – Dennis Dec 29 '18 at 08:47
  • After updating `Dockerfile` you need to rebuild it. You can do it manually running `docker build -t my-image .` in the folder, containing `Dockerfile` and then refer it as `my-image`. Or you may configure `docker-compose` to do that. – grapes Dec 29 '18 at 08:52
  • Great, thanks! But when working in a dev team, what is the best approach? I can't ask everybody to run docker build. So updating docker-compose will be the best way? How does it look like? – Dennis Dec 29 '18 at 12:32
  • Simple. Update you `docker-compose.yml` according to this doc: https://docs.docker.com/compose/compose-file/#build and launch `docker-compose` with `--build` argument. – grapes Dec 29 '18 at 16:53
0

According to offical image doc:

If you are having difficulty figuring out which Debian or Alpine packages need to be installed before docker-php-ext-install, then have a look at the install-php-extensions project. to install the GD extension you simply have to add these to lines to Dockerfile and get ride of everty things:

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
    install-php-extensions gd
Mahdi Younesi
  • 6,889
  • 2
  • 20
  • 51