How to install yarn and npm on a PHP docker image (symfony 4 project)

Im working on a symfony 4/posgresql project. Im using docker toolbox.

I need to install webpack encore bundle on symfony, but in order to do this, i need to add yarn and npm to my project. Somebody told me i should add theses 2 installations on my php docker container, but i don’t know which command to add (im a linux/docker beginner).

This is my docker-compose.yaml :

 
services:
  database:
    image: postgres:11-alpine
    ports:
        - "5432:5432"
    volumes:
      - 'boeki_database:/var/lib/postgresql/data'
    environment:
      POSTGRES_PASSWORD: root
 
  database_pg_admin:
    image: dpage/pgadmin4
    ports:
        - "8001:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: [email protected]
      PGADMIN_DEFAULT_PASSWORD: root
       
  application:
    build:
      context: .
      dockerfile: ./docker/Dockerfile
    working_dir: /var/www/project
    ports:
        - "8000:80"
    volumes:
      - ./:/var/www/project:rw,cached
      - ./docker/http/000-default.conf:/etc/apache2/sites-enabled/000-default.conf:rw,cached
 
volumes:
  boeki_database: {} 

And this is my Dockerfile :

 
RUN apt-get update && 
    apt-get install -y libpq-dev g++ zlib1g-dev libicu-dev vim git zip
 
#GD
RUN apt-get update && 
  DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends 
  libfreetype6-dev 
  libjpeg62-turbo-dev 
  libpng-dev 
  libzip-dev 
  poppler-utils
 
RUN rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype --with-jpeg && 
  docker-php-ext-install -j "$(nproc)" gd pdo_pgsql
 
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo pdo_mysql intl zip opcache
 
RUN pecl install redis && echo "extension=redis.so" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini
 
RUN a2enmod rewrite
 
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

Thanks for the help !

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *