skip to Main Content

I have been trying to Dockerizing Magento 2.4.3-p2 on my Ubuntu 22.04. So here is my

`docker-compose.yml
version: '3.0'

services:
  nginx:
    build:
      context: .
      dockerfile: docker/nginx/dockerfile
    ports:
      - '8000:80'
    volumes:
      - ./docker/nginx/conf.d:/etc/nginx/conf.d
      - ./src:/var/www/html
    restart: always

  php-fpm:
    build:
      context: .
      dockerfile: docker/php/dockerfile
    volumes:
      - ./src:/var/www/html 
    depends_on:
      - nginx
  
  db:
    image: mariadb:10.4.13
    ports:
     - 3300:3306
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=magento
      - MYSQL_USER=magento
      - MYSQL_PASSWORD=magento
    volumes:
      - dbdata:/var/lib/mysql
    depends_on:
      - nginx
      - php-fpm

  redis:
    image: redis:6.2-alpine
    ports:
      - "6379:6379"
  
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
    ports:
      - "9200:9200"
    environment:
      - discovery.type=single-node

  memcached:
    image: memcached:1.5
    ports:
      - "11211:11211"

  varnish:
    image: varnish:latest
    ports:
      - "8080:80"
    depends_on:
      - nginx

  composer:
    image: composer:2.3
    volumes:
      - ./magento:/var/www/html
    working_dir: /var/www/html



volumes:
  dbdata:`

`nginx dockerfile

FROM nginx:1.18.0-alpine-perl

ARG APP_ID=1000

RUN addgroup -g "$APP_ID" app 
 && adduser -G app -u "$APP_ID" -h /var/www/html -s /bin/bash -S app
RUN touch /var/run/nginx.pid
RUN mkdir /sock

USER app:app

VOLUME /var/www/html

WORKDIR /var/www/html`

`Nginx conf file

server {
    listen 80;
    server_name loaclhost

    root /var/www/html; # Magento root directory

    index index.php;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ .php$ {
        include fastcgi_params;
        fastcgi_pass php-fpm:9000; # Connect to PHP-FPM container
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /.ht {
        deny all;
    }
}

Php dockerfile

FROM php:7.4.0-fpm-buster

ARG APP_ID=1000
RUN groupadd -g "$APP_ID" app 
  && useradd -g "$APP_ID" -u "$APP_ID" -d /var/www/html -s /bin/bash app

RUN apt-get update && apt-get install -y 
    libfreetype6-dev 
    libjpeg62-turbo-dev 
    libpng-dev 
    libwebp-dev 
    libxpm-dev 
    libzip-dev 
    libicu-dev 
    libmcrypt-dev 
    libxslt-dev 
    libxslt1-dev 
    libcurl4-openssl-dev 
    libxml2-dev 
    libonig-dev 
    unzip 
    git 
    nano 
    && apt-get clean 
    && rm -rf /var/lib/apt/lists/*


RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp --with-xpm 
    && docker-php-ext-install -j$(nproc) gd 
    && docker-php-ext-configure intl 
    && docker-php-ext-install -j$(nproc) intl 
    && docker-php-ext-install -j$(nproc) pdo_mysql 
    && docker-php-ext-install -j$(nproc) xsl 
    && docker-php-ext-install -j$(nproc) zip 
    && docker-php-ext-install -j$(nproc) bcmath 
    && docker-php-ext-install -j$(nproc) soap 
    && docker-php-ext-install -j$(nproc) sockets

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer


COPY . /var/www/html

EXPOSE 9000

CMD ["php-fpm"]

WORKDIR /var/www/html`

I run each container indiuvally and checked them. But when I’m running
sudo docker run --rm -it --volume $(pwd)/src:/var/www/html composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.3-p2 . --ignore-platform-req=ext-intl

To install the Magento locally. I’m getting an error.

Problem 1 - Root composer.json requires magento/product-community-edition 2.4.3-p2 -> satisfiable by magento/product-community-edition[2.4.3-p2]. - magento/product-community-edition 2.4.3-p2 requires php ~7.3.0||~7.4.0 -> your php version (8.2.10) does not satisfy that requirement.

Although I am clearly using php:7.4.0-fpm-buster in my setup. To avoid the confit I have purged PHP from my local machine as well. What should I do to resolve the issue?

2

Answers


  1. There are multiple ways you can resolve the error of not matching the PHP platform version for your containerized composer invocation.

    Answering to the initial composer project configuration creation statement in your question I was able to find (composer create-project) adding the --ignore-platform-reqs command line argument should prevent the error message.

    In general what is going on is that when you call composer containerized, it is using the container-configured PHP version (8.2.10) and is not using a different (the expected, more aged 7.x PHP version) that may be in a different container, but is out of scope for composer to detect, as Composer has been containerized, and with that level of isolation, any different than the containerized PHP version is out of reach for composer and can not be inferred from within the container environment.

    However, there are both command-line arguments/environment parameters and composer.json project (and perhaps even global) configuration settings, that may allow you to make use of to command Composer to not rely on inference but instead stick to your commandment and/or configuration for the PHP version and any other platform package (and perhaps a bit out of scope in regard of your question: also any project package).

    Please see the Composer documentation for all composer command-line arguments, environment parameters (often called environment variables), the whole composer.json schema and last but not least all configuration and options.

    Also you may want to follow the pattern of a build container with a multi-stage build that is using the production version of PHP you target as your platform version, copies composer.phar (or its equivalent executable) into the containerized build environment, creates the project there and then, finally, copies from that stage the actual result into the final image where you’d like to prepare the mount. Mind thought you’re matching the mount strategy you’re trying to do here, because depending on the kind of mind and order to mount, you may require to apply a file copy operation (e.g. prepared in a tarball) after mounting.

    The docker-compose.yml based configuration should provide you all the options despite which build pattern you’re trying to follow, even if you use a little dated docker version, just take care you’re able to use docker compose V2.

    For Composer and PHP keep the containerization in mind, that is, docker run will always be within it’s own container and can only be what the image of it provides.

    Login or Signup to reply.
  2. It looks like you’re running composer in the composer container, not the php Dockerfile you created.

    To break this down:

    sudo docker run --rm -it --volume $(pwd)/src:/var/www/html composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.3-p2 . --ignore-platform-req=ext-intl
    
    docker run  # the command
    --rm -it    # remove container after use and run with interactive mode
    --volume $(pwd)/src:/var/www/html  # mount $(pwd)/src into container
    composer    # the image you are running
    create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.3-p2 . --ignore-platform-req=ext-intl # the command you are wanting to run in the composer image
    

    So that will run using the version of PHP in the composer container, not the one in your Dockerfile

    To try and fix this, as you are installing composer into your docker image, I would replace the composer service with a PHP service in your docker-compose.yaml and then use docker compose run php-service-name create-project ... to run the composer command with the correct version of PHP and dependencies.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search