Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker php:7.1-fpm-alpine fails to build GD

Trying to build from the official php:7.1-fpm-alpine image, using the following excerpt in my Dockerfile:

FROM php:7.1-fpm-alpine

RUN set -ex \
    apk add --no-cache --virtual .build-deps \
    freetype-dev \
    libjpeg-turbo-dev \
    libpng-dev \
\
    && docker-php-ext-configure gd \
        --with-freetype-dir=/usr \
        --with-png-dir=/usr \
        --with-jpeg-dir=/usr \
    && docker-php-ext-install gd \
    && apk del .build-deps

When attempting to build this with docker build, GD fails during ./configure with the following error:

configure: error: jpeglib.h not found

I can confirm that jpeglib.h exists and is exactly where I think it should be (indeed, exactly where it is in Debian variants):

$ docker run -it --rm php:7.1-fpm-alpine /bin/sh
>$ apk add --no-cache libjpeg-turbo-dev \
   && find /usr -type f -name 'jpeglib.h'
   ...
   /usr/include/jpeglib.h

But if I take exactly the same command used in the dockerfile and run it interactively inside the container, it builds flawlessly. No errors.

Is this a bug, or am I missing something?

like image 360
deixismou Avatar asked Mar 19 '17 07:03

deixismou


1 Answers

The problem was a blindingly simple syntax error; the apk call following the set command needs to be preceded by &&, otherwise the interpreter is treating the entire apk call as a set of arguments to set. In that case, the packages aren't added, therefore jpeglib.h didn't exist.

When I typed the command into the shell, I used the correct syntax, so it passed without error.

like image 116
deixismou Avatar answered Sep 30 '22 01:09

deixismou