skip to Main Content

it’s my first time using Docker in a project (a Symfony project). In this project i don’t have any database, i just want to have the PHP version (8.3.1) and the projects dependencies.

This is the error i get when i do docker compose up –build :

1.025 Executing script cache:clear [KO] 1.031 [KO] 1.031 Script cache:clear returned with error code 1
1.031 !! Could not open input file: ./bin/console
1.031 !!
1.031 Script @auto-scripts was called via post-install-cmd

failed to solve: process "/bin/sh -c composer install –no-dev –no-interaction" did not complete successfully: exit code: 1

This is my Dockerfile :

FROM composer:lts as deps

WORKDIR /app

RUN --mount=type=bind,source=composer.json,target=composer.json 
    --mount=type=bind,source=composer.lock,target=composer.lock 
    --mount=type=cache,target=/tmp/cache 
    composer install --no-dev --no-interaction

FROM php:8.3.1-apache as final

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

COPY --from=deps app/vendor/ /var/www/html/vendor

COPY src /var/www/html

USER www-data

This is my compose.yml file :

services:
server:
build:
context: .
ports:
– 9000:80

I tried to find a solution online but i found nothing recent related to Symfony with Docker

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for your help carloliwanag, i had to add two lines to make it works.

    This is my code right now :

    FROM php:8.3.1-apache
    
    #Update and install php dependencies
    RUN apt-get update && 
        apt-get install nano zip unzip wget git locales locales-all libcurl4-openssl-dev libjpeg-dev libpng-dev libzip-dev pkg-config libssl-dev -y && 
        docker-php-ext-install pdo_mysql bcmath
    RUN pecl install mongodb && docker-php-ext-enable mongodb
    
    RUN docker-php-ext-configure gd 
        && docker-php-ext-install gd 
        && docker-php-ext-enable gd
    
    RUN docker-php-ext-configure zip 
        && docker-php-ext-install zip
    
    # Copy code
    WORKDIR /var/www/html/
    
    COPY src .
    
    COPY composer.json .
    
    # install composer
    RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && 
        php composer-setup.php && 
        php -r "unlink('composer-setup.php');" && 
        mv composer.phar /usr/local/bin/composer
    
    # install project php dependencies
    ENV COMPOSER_ALLOW_SUPERUSER=1
    
    RUN composer install
    

  2. It seemed to me that you are running composer install before copying your src folder to /var/www/html.

    I would suggest to

    1. start with the base PHP image
    2. move the src folder
    3. install composer
    4. run composer install.

    In your case it will be something like:

    FROM php:8.3.1-apache
    
    #Update and install php dependencies
    RUN apt-get update && 
        apt-get install nano zip unzip wget git locales locales-all libcurl4-openssl-dev libjpeg-dev libpng-dev libzip-dev pkg-config libssl-dev -y && 
        docker-php-ext-install pdo_mysql bcmath
    RUN pecl install mongodb && docker-php-ext-enable mongodb
    
    RUN docker-php-ext-configure gd 
        && docker-php-ext-install gd 
        && docker-php-ext-enable gd
    
    RUN docker-php-ext-configure zip 
        && docker-php-ext-install zip
    
    # Copy code
    WORKDIR /var/www/html/
    
    COPY src .
    
    # install composer
    RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && 
        php composer-setup.php && 
        php -r "unlink('composer-setup.php');" && 
        mv composer.phar /usr/local/bin/composer
    
    # install project php dependencies
    RUN composer install
    
    # Other layers follow
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search