The issue you're encountering is due to the fact that the composer:latest image you are using in your composer.dockerfile might be based on a different PHP version than the one specified in your php.dockerfile. The composer:latest image could be using PHP 8.3, which is causing the version conflict.
To resolve this, you can create a custom Composer image that uses the same PHP version (8.2) as your application. Here's how you can modify your composer.dockerfile to ensure it uses PHP 8.2:
- Create a custom Composer Dockerfile based on PHP 8.2:
# composer.dockerfile
FROM php:8.2-cli-alpine
ARG UID
ARG GID
ENV UID=${UID}
ENV GID=${GID}
RUN apk add --no-cache \
libzip-dev \
unzip \
git \
&& rm -rf /var/cache/apk/*
RUN addgroup -g ${GID} --system laravel
RUN adduser -G laravel --system -D -s /bin/sh -u ${UID} laravel
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
-
Update your
docker-compose.ymlto use the custom Composer image:
services:
nginx:
build:
context: .
dockerfile: nginx.dockerfile
ports:
- 8080:80
volumes:
- ./src:/var/www/html
depends_on:
- mysql
- php
mysql:
image: mysql:8
environment:
MYSQL_DATABASE: laravel
MYSQL_USER: laravel
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
volumes:
- ./mysql:/var/lib/mysql
php:
build:
context: .
dockerfile: php.dockerfile
args:
- UID=${UID:-1000}
- GID=${GID:-1000}
volumes:
- ./src:/var/www/html
composer:
build:
context: .
dockerfile: composer.dockerfile
args:
- UID=${UID:-1000}
- GID=${GID:-1000}
volumes:
- ./src:/var/www/html
user: laravel
working_dir: /var/www/html
npm:
image: node:current-alpine
volumes:
- ./src:/var/www/html
entrypoint: ["npm"]
working_dir: /var/www/html
artisan:
build:
context: .
dockerfile: php.dockerfile
args:
- UID=${UID:-1000}
- GID=${GID:-1000}
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- mysql
entrypoint: ['php', "/var/www/html/artisan"]
By creating a custom Composer image based on PHP 8.2, you ensure that the PHP version used by Composer matches the PHP version used by your application, thus resolving the version conflict.