1

Running Laravel on an appache server.

Upon building the image with docker-compose up --build with the following Dockerfile

FROM php:7.3-apache-stretch
RUN apt-get update -y && apt-get install -y libpng-dev
RUN docker-php-ext-install pdo pdo_mysql gd

FROM composer:1.9.0 as build
WORKDIR /app
COPY . /app
RUN composer global require hirak/prestissimo && composer install

I am getting the error message:

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

This happens when the composer install command runs.

As you can see up, I am actually installing gd from php, so it should not give me this error message.

Do you have any idea how I can solve it?

Thanks!

2
  • Does this help? (Not marking it as dupe as I'm unsure it's the same scenario, looks close though.) Commented Aug 9, 2020 at 13:01
  • No it doesn't work. Similar error message.. Commented Aug 9, 2020 at 13:30

2 Answers 2

1

It's happen, because you are using multistage building and your composer second stage have nothing to do with previous build using PHP container. Primary use case with multistaging is to produce some useful artefacts which can be used later.

So what I suggest is to copy composer file from composer image, then place it somewhere in your php container.

I will give you my solution which is working perfectly for me with laravel/symfony etc.

FROM php:7.4.4-fpm

# We copy composer from it's original image to our php container to use it later.
COPY --from=composer:1.9 /usr/bin/composer /usr/bin/composer

WORKDIR /var/www

ARG USER_ID

RUN useradd -s /bin/bash -d /home/user/ -m -G sudo,www-data user -u $USER_ID

RUN apt update && apt install -y zip unzip wget zlib1g-dev libicu-dev

RUN docker-php-ext-install pdo_mysql intl opcache gd

USER user

RUN wget https://get.symfony.com/cli/installer -O - | bash

ENV PATH="/home/user/.symfony/bin:${PATH}"

COPY php.ini /usr/local/etc/php

# You can also run here composer install, depends on your use case
Sign up to request clarification or add additional context in comments.

3 Comments

So what you would suggest us to copy composer as you did, and then simply RUN composer install and this should work?
Exactly, but you have to be sure, that you put your composer file to bin directory, where commands can be globally evaluated by your shell.
I see, thank you for the clarification. It was really helpful to see my conceptual mistake.
0

You can change your docker image. For example try this:

FROM richarvey/nginx-php-fpm
WORKDIR /app
RUN php ./artisan config:cache && composer install

Comments

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.