8

I'm getting this error when trying to deploy using alpine:

phpoffice/phpspreadsheet 1.2.1 requires ext-gd * -> the requested PHP extension gd is missing from your system.

Here's my Dockerfile:

FROM php:7.2-alpine

RUN apk update
RUN apk add zlib-dev gd php7-gd
RUN docker-php-ext-install sockets pdo_mysql zip
RUN apk add --no-cache libpng libpng-dev && docker-php-ext-install gd

The error is an output from a jenkins run. I think it's failing somewhere around here...

build:
    docker run --rm --tty --user $$(id -u):$$(id -g) \
        --volume "$$(pwd)":/app \
        --volume "$$(pwd)/ops/jenkins/github.token":/tmp/auth.json \
        --volume "$$(pwd)/ops/jenkins/composer_trust_github.com":/root/.ssh/config \
        composer install --no-dev
    rm -rf ops/docker/app.tar.gz
    tar -czvf ops/docker/app.tar.gz -X ops/jenkins/build_excludes .

docker run --rm --tty --user $(id -u):$(id -g) \
    --volume "$(pwd)":/app \
    --volume "$(pwd)/ops/jenkins/github.token":/tmp/auth.json \
    --volume "$(pwd)/ops/jenkins/composer_trust_github.com":/root/.ssh/config \
    --volume "$(pwd)/ops/jenkins/php/php.ini":/usr/local/etc/php/php.ini \
    composer install --no-dev
[32mLoading composer repositories with package information[39m
[32mInstalling dependencies from lock file[39m
[37;41mYour requirements could not be resolved to an installable set of packages.[39;49m

  Problem 1
    - Installation request for phpoffice/phpspreadsheet 1.2.1 -> satisfiable by phpoffice/phpspreadsheet[1.2.1].
    - phpoffice/phpspreadsheet 1.2.1 requires ext-gd * -> the requested PHP extension gd is missing from your system.

How do I correctly add ext-gd?


UPDATE: More information

The commands of the Makefile which Jenkins calls in order are as follows:

prepare:
    git clone git@github.com:xxx/go-php-sqs-consumer
    cd go-php-sqs-consumer && glide install
    docker run --rm -v "${PWD}/go-php-sqs-consumer":/go/src/app -w /go/src/app golang:1.8.1-alpine go build -o consumer
    mv go-php-sqs-consumer/consumer ops/docker/consumer
    rm -rf go-php-sqs-consumer

build:
    echo "{\"github-oauth\":{\"github.com\":\"$$(credstash get github.tech-craft.jenkins-eu-west-1)\"}}" > ops/jenkins/github.token
    docker run --rm --tty --user $$(id -u):$$(id -g) \
        --volume "$$(pwd)":/app \
        --volume "$$(pwd)/ops/jenkins/github.token":/tmp/auth.json \
        --volume "$$(pwd)/ops/jenkins/composer_trust_github.com":/root/.ssh/config \
        composer install --no-dev
    rm -rf ops/docker/app.tar.gz
    ansible-vault decrypt config.*.json && chmod a+r config.*.json
    tar -czvf ops/docker/app.tar.gz -X ops/jenkins/build_excludes .

archive:
    aws s3api put-object --bucket craft-build --key "auth-api/${s3_key_version}.tar.gz" --body "ops/docker/app.tar.gz"
    aws s3api put-object --bucket craft-build --key "auth-api/current.tar.gz" --body "ops/docker/app.tar.gz"

containerise:
    cd ops/docker && docker build --pull --no-cache -t application-exporter-service .
3
  • Are you sure you are using the correct image? Just created Dockerfile locally (exactly as yours) and added composer to it. phpoffice/phpspreadsheet installs without any issues. Apr 24, 2018 at 11:23
  • See my update. I don't know if that makes more sense. I don't know how docker run is even working without defining an image to actually run. This is a colleagues code who has run off and left me alone to handle. The tutorials I've seen, docker run normally follows with something like .. nginx:latest. Apr 24, 2018 at 12:14
  • 1
    It works exactly as expected. The docker run uses a composer image and executes an install --no-dev command inside it. Then it packs everything as a tar archive (for release, I guess). Try to change the command to install --no-dev --ignore-platform-reqs --no-scripts Apr 24, 2018 at 13:01

3 Answers 3

20

Here's how I do it but on php image, not alpine. Maybe you can just "finetune" it to work on alpine:

RUN apt-get update && \
    apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng12-dev && \
    docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-install gd
3
  • php:7.3-fpm gives me a error: libpng12-dev is not found, maybe you can adjust your answer
    – yooouuri
    Dec 14, 2018 at 12:52
  • 3
    you can use libpng-dev instead of libpng12-dev
    – LPodolski
    Mar 23, 2019 at 18:45
  • In my case (image php:7.1-apache) libpng-dev' is mandatory, otherwise: E: Package 'libpng12-dev' has no installation candidate
    – funder7
    Jan 31, 2022 at 23:43
9

It's help for me:

RUN apk update

RUN apk add libpng libpng-dev libjpeg-turbo-dev libwebp-dev zlib-dev libxpm-dev gd && docker-php-ext-install gd
0

I'm with Izydorr. In addition to that, you could also create your own docker registry and modify a small baseimage for your needs and use it as a build image for jenkins.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.