Home > database >  PHP-FPM Alpine Docker Image 7.4 installs PHP version 8.0
PHP-FPM Alpine Docker Image 7.4 installs PHP version 8.0

Time:12-02

since the latest php fpm docker image update yesterday (https://hub.docker.com/_/php?tab=tags&page=1&name=fpm-alpine) my pipeline is broken because apparently PHP version 8 is installed instead of 7.4 as in my Dockerfile specified.

I am using this in my docker file:

FROM php:7.4-fpm-alpine AS ...

But according to my composer installs the container has PHP 8.0.13 running:

 Root composer.json requires php 7.4.26 but your php version (8.0.13) does not satisfy that requirement.

Anyone an idea what is going on here?

CodePudding user response:

As Jeremy Brooks already mentioned, Alpine released version 3.15 where composer requires PHP 8 (https://pkgs.alpinelinux.org/package/v3.15/community/x86_64/composer). Instead of installing composer from getcomposer.org another solution is to use Alpine 3.14:

FROM php:7.4-fpm-alpine3.14 AS ...

CodePudding user response:

You are running composer from the hosts command line (where you installed PHP 8) instead of inside the container.

CodePudding user response:

I may have hit the same issue. Those alpine PHP images do not include composer, so how are you installing it? If you are using apk, it looks like the latest alpine composer package is pulling php8 in as a dependency. What solved this issue for me is to install composer using the install script from getcomposer.org instead of using apk. Assuming this is what you are doing, remove this from your Dockerfile:

RUN apk add composer

and add:

ADD https://getcomposer.org/installer ./composer-setup.php
RUN php ./composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN rm ./composer-setup.php

If composer is indeed included in your base image, you could try uninstalling first:

RUN apk delete composer

and then add the above code to install it from the setup script instead.

Edit: adding the ignore-platform-reqs flag will probably get you past the error, but you are introducing a possible point of failure in the future if you have a composer package with a platform requirement. In that case, you won't know about the error until runtime. I would not recommend that approach. The method I posted above will install composer using the version of PHP already on the system and will not require risky workarounds.

CodePudding user response:

I'm currently working on my docker-compose file to install laravel 8 with php 8.

I tested "php:7.4-fpm-alpine", and when I access the container I'm getting this version of php :

/var/www/html # php --version  
PHP 7.4.26 (cli) (built: Nov 30 2021 08:21:51) ( NTS )

You can test it yourself :

docker container ls
docker exec -it <container_id> sh
php --version

I'm getting PHP 8.0.13 when installing "php:8.0-fpm-alpine"

Also I'm creating my laravel project using the composer image, I don't have php/composer installed locally. It's something you might have a look, because it could be quickly confusing ;-)

CodePudding user response:

I had the same problem today...

Try:

  • composer install --no-scripts --ignore-platform-reqs

Fixed it for me.

Code and Idea are from https://stackoverflow.com/users/564000/armin

  • Related