Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup laravel with npm using docker-compose?

I have the next docker-compose.yml file

version: '2'
services:
  # The Application
  app:
    build:
      context: ./
      dockerfile: app.dockerfile
    working_dir: /var/www/html
    volumes:
      - ./giftmeabetterplanet:/var/www/html
    environment:
      - "DB_PORT=3306"
      - "DB_HOST=database"

  # The Web Server
  web:
    build:
      context: ./
      dockerfile: web.dockerfile
    working_dir: /var/www/html
    links:
      - database:mysql
    volumes_from:
      - app
    ports:
      - 81:80
    environment:
      - "WEB_DOCUMENT_ROOT=/var/www/html/public"
  # The Database
  database:
    image: mysql:5.6
    volumes:
      - dbdata:/var/lib/mysql
    environment:
      - "MYSQL_DATABASE=homestead"
      - "MYSQL_USER=homestead"
      - "MYSQL_PASSWORD=secret"
      - "MYSQL_ROOT_PASSWORD=secret"
    ports:
        - "3306"

volumes:
  dbdata:

I need to make NPM (node package manager) accessible somehow to build my JS and CSS files in 'web' container.

app.dockerfile

FROM php:7.0.4

RUN apt-get update && apt-get install -y libmcrypt-dev \
    mysql-client libmagickwand-dev --no-install-recommends \
    && pecl install imagick \
    && docker-php-ext-enable imagick \
    && docker-php-ext-install mcrypt pdo_mysql

web.dockerfile

FROM webdevops/php-apache-dev:ubuntu-16.04

I've tried the next way by extending web.dockerfile

FROM orlandohohmeier/local-npm
FROM webdevops/php-apache-dev:ubuntu-16.04

But npm is not accessible from the command line in 'web' container. Maybe i don't understand some concepts but i just want to compile my stiles, javascript files and copy fonts from node-modules.

Best regards. Ivan

like image 936
Bitrix24 Avatar asked Sep 16 '17 22:09

Bitrix24


2 Answers

For PHP7.2 this is what I have in my php.dockerfile

RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - RUN apt-get install -y nodejs

like image 54
Dele Avatar answered Sep 23 '22 09:09

Dele


Add to the docker-compose file

npm:  
  image: node:14
  working_dir: /var/www/my_shiny_project
  entrypoint: ["npm"]
  volumes: 
    - "./www/:/var/www/my_shiny_project"

Usage:

docker-compose run --rm npm install

Don't forget to check the paths in both working_dir and volumes

like image 26
pszaba Avatar answered Sep 24 '22 09:09

pszaba