R
R
Ramil2018-03-06 17:03:08
Node.js
Ramil, 2018-03-06 17:03:08

How to install npm dependencies inside Docker container?

I have node server. I run it for development through docker. When I want to add a new module, I go into the container and do yarn add express for example. In this case, everything works.
And if I directly add the dependency to package.json by hand, and then do docker-compose up --build or docker-compose build, then the package will not install. Why is that?
And another question, why is the node_modules folder on my host empty, but not in the container?
docker-compose.yml:

version: '3'

services:
  app:
    build: ./
    command: yarn run dev
    restart: always
    ports:
      - "3000:3000"
    volumes:
      - .:/usr/app
      - /usr/app/node_modules

Dockerfile:
FROM node:latest
WORKDIR /usr/app
COPY package.json ./
RUN yarn

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question