Home  >  Q&A  >  body text

How to roll back to PHP version 8.1: Docker phpdockerio/php:8.1-fpm build uses PHP version 8.2

I'm running my project on a PHP-FPM docker container (config file details below). When I build the container and try to run Composer, I get an error reporting that the PHP extension is missing. However, I think my build file covers these extensions (see docker/php-fpm/Dockerfile below).

It turns out that the container was built with php8.2 as the default version. I've been able to change the symlink to set the default version back to php8.1 but this doesn't seem to be the right solution. Can anyone suggest a better solution?

How do I know the container is running 8.2: Inside the container I run php --version and get:

root@fee8cc9ff790:/application# php --version
PHP 8.2.0 (cli) (built: Dec  8 2022 13:56:08) (NTS)

Then which php gave me:

root@fee8cc9ff790:/application# which php
/usr/bin/php

I followed the symlink to the PHP binary linked in /etc/alternatives:

phar -> /usr/bin/phar8.2
phar.phar -> /usr/bin/phar.phar8.2
php -> /usr/bin/php8.2
phpdbg -> /usr/bin/phpdbg8.2

This doesn't seem right to me. I was able to relink them to their 8.1 versions and everything seems to be running fine now, but what happens when I rebuild the container?

My file details:

docker-compose.yml

###############################################################################
#                          Generated on docker.io                          #
###############################################################################
version: '3.9'
services:
    mailhog:
        image: 'mailhog/mailhog:latest'

    redis:
        image: 'redis:alpine'

    mysql:
        image: 'mysql:8.0.27'
        working_dir: /application
        platform: linux/amd64
        environment:
            - MYSQL_ROOT_PASSWORD=
            - MYSQL_DATABASE=
            - MYSQL_USER=
            - MYSQL_PASSWORD=

    webserver:
        image: 'nginx:alpine'
        working_dir: /application
        volumes:
            - '.:/application'
            - './docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf'

    php-fpm:
        build: docker/php-fpm
        working_dir: /application/
        volumes:
            - '.:/application'
            - './docker/php-fpm/php-ini-overrides.ini:/etc/php/8.1/fpm/conf.d/99-overrides.ini'
            - './docker/php-fpm/php-ini-overrides.ini:/etc/php/8.1/cli/conf.d/99-overrides.ini'

docker-compose.override.yml

###############################################################################
#                          Generated on phpdocker.io                          #
###############################################################################
version: '3.9'
services:

    mailhog:
        ports:
            - '8026:8025'

    mysql:
        ports:
            - '33061:3306'

    webserver:
        ports:
            - '801:80'

docker/php-fpm/Dockerfile

FROM phpdockerio/php:8.1-fpm
WORKDIR "/application"

RUN apt-get update; 
    apt-get -y --no-install-recommends install 
        git 
        php-xdebug 
        php8.1-mysql 
        php8.1-sqlite 
        mysql-client 
        php8.1-redis; 
    apt-get clea  n; 
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*


P粉757640504P粉757640504323 days ago701

reply all(1)I'll reply

  • P粉418854048

    P粉4188540482023-11-06 09:14:25

    This turned out to be caused by the extension I was loading. In docker/php-fpm/Dockerfile I installed php-xdebug which caused the container to load PHP8.2

    Specify version 8.1php8.1-xdebugSolved the problem.

    Thanks to luispabon for his response to my question on GitHub, who thought it must be an issue with the images. https://github.com/phpdocker-io/base-images/issues/ 62

    reply
    0
  • Cancelreply