Docker phpdockerio/php:8.1-fpm builds with PHP version 8.2: How can I revert to 8.1?

I’m running my project on a PHP-FPM docker container (details of config files below). When I build my containers and attempt to run composer I’m getting errors reporting missing PHP extensions. However, I thought my build files where covering these extensions (see docker/php-fpm/Dockerfile below).

It turns out that the container is being built with php8.2 as the default version. I have been able to change the symlinks to set the default version back to php8.1 but this doesn’t seem like the right solution. Can anyone suggest a better fix?

How I know the container is running 8.2:
Inside the container I ran php --version and got:

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 symlinks to find that linked PHP binaries in /etc/alternatives are:

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

This is the bit that doesn’t seem right to me. I was able to relink these to their 8.1 versions and things seem to be running fine now but what happens when I rebuild the container?

Details of my files:

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 clean; 
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*