I need to downgrade composer in docker. How?

This is the error I get:

#10 1.635 Composer 2.3.0 dropped support for PHP <7.2.5 and you are running 7.1.33, please upgrade PHP or use Composer 2.2 LTS via “composer self-update --2.2”. Aborting.

I need to run php7.1 due to Laravel 5.3

To put in other words: you have issues with an image that you use?

You are free to pick any image that provides the versions of components that you need. If you don’t find an image that meets your needs, you can still build your own image that does exactly what you are looking for.

Well, to be honest I’m not so familiar with Docker. These are the images in Docker.
|mysql||5.7|f26e21ddd20d|16 days ago|449.62 MB|RUN|
|nginx||1.21|12766a6745ee|16 days ago|141.52 MB|RUN|
|redis||alpine|34e1dc356a22|9 days ago|32.37 MB|RUN|
|webshooter||latest|d79e38225efc|3 days ago|1.22 GB|RUN|

But I don’t know how to handle these and how to provide composer 2.2 to which image.
This is the Dockerfile that’s used:

FROM php:7.1-apache

LABEL maintainer="Webshooter LM AB <support@webshooter.se>" \
    version="1.0"

WORKDIR /var/www/html

RUN apt-get update && \
    apt-get install -y \
    gpg \
    software-properties-common \
    ruby \
    build-essential \
    zlib1g-dev \
    locales \
    npm \
    ruby-dev \
    libpng-dev \
    libssl-dev \
    libffi-dev \
    mercurial \
    python \
    python-dev \
    python-pip \
    libonig-dev \
    libxml2-dev \
    beanstalkd \
    mariadb-client \
    supervisor && \
    npm install --global gulp-cli && \
    locale-gen sv_SE.utf8

RUN docker-php-ext-install pdo_mysql exif pcntl bcmath gd zip

ENV API_VERSION=4.1.9

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

RUN composer global require "laravel/installer"

# If we need cronjobs we need to make this work, skipping for now
# RUN pip install -e hg+https://bitbucket.org/dbenamy/devcron#egg=devcron

COPY --chown=www-data:www-data package.json .

RUN npm install --production

# Then do Laravel

COPY --chown=www-data:www-data app ./app/
COPY --chown=www-data:www-data bootstrap ./bootstrap/
COPY --chown=www-data:www-data config ./config/
COPY --chown=www-data:www-data database ./database/
COPY --chown=www-data:www-data public ./public/
COPY --chown=www-data:www-data resources ./resources/
COPY --chown=www-data:www-data routes ./routes/
COPY --chown=www-data:www-data tests ./tests/
COPY --chown=www-data:www-data artisan composer.json gulpfile.js server.php ./

RUN composer install  --no-ansi --no-dev --no-interaction \
    --no-progress --no-scripts --optimize-autoloader

RUN gulp --production

COPY --chown=root:root ./resources/crontab /etc/cron.d/laravel

# Apache

COPY ./resources/vhost.conf /etc/apache2/sites-available/site.conf
RUN a2dissite 000-default.conf && a2ensite site.conf && a2enmod rewrite

# Only for FPM
#COPY ./resources/php-fpm.conf /usr/local/etc/php-fpm.conf
#COPY ./resources/php-fpm.www.conf /usr/local/etc/php-fpm.d/www.conf

RUN touch /var/log/cron.log

RUN chmod 777 /run
RUN chmod 770 /home

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY --chown=www-data:www-data ./deploy/entrypoint.sh /usr/local/bin/entrypoint-ws.sh
RUN chmod +x /usr/local/bin/entrypoint-ws.sh 

COPY --chown=www-data:www-data ./deploy/initialize.sh ./
RUN chmod +x ./initialize.sh

COPY ./deploy/supervisor-webshooter.conf /etc/supervisor/conf.d/

ENTRYPOINT ["entrypoint-ws.sh"]
CMD ["apache2-foreground"]

EXPOSE 80

Here is the total error:

=> CACHED [stage-0 5/31] COPY --from=composer:latest /usr/bin/composer /usr/bin/composer 0.0s
=> ERROR [stage-0 6/31] RUN composer global require “laravel/installer” 1.8s

[stage-0 6/31] RUN composer global require “laravel/installer”:
#11 1.603 Composer 2.3.0 dropped support for PHP <7.2.5 and you are running 7.1.33, please upgrade PHP or use Composer 2.2 LTS via “composer self-update --2.2”. Aborting.


failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c composer global require “laravel/installer”]: exit code: 1
Ralphs-MacBook:deploy ralph$

I have no experience with any or the componets in the image, but it looks like it is as easy as replacing:

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

with

COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer

Right now the tag 2.2 points to the same image as 2.2.12.

Please change the line and try to build the image again!

Yes! That did the trick. Thanks a lot, Should have thought of that, I saw it said “latest” but it have worked before so… One thing I did a while ago was upgrading my Mac OS BigSur from 11.6.1 to 11.6.5, could that have to do something with the error?
Thanks again!

latest pointed to an image that was 2.2.x at one point.
By convention the latest tag points to the most recent verion’s image, which at one point became a 2.3.x image.

While the mutable tag 2.2 is less problematic, as it points to the current 2.2.x version, the mutable tag latest can be problematic as it will be the current major.minor.patch version.

Right. And we are using an old Laravel system version 5.3 in local docker as reference for upgrading to Laravel 8 at the moment. It look like this: https://test.webshooter.se (still at 5.3)
It’s a pistol competition system to create and handle competitions, shooters registered, result handling etc.