title: Install a new node dependency inside a Docker container
body: <p>Considering the following development environment with Docker:</p>
  
  <pre><code># /.env
  CONTAINER_PROJECT_PATH=/projects/my_project
  
  # /docker-compose.yml
  version: '2'
  services:
    web:
      restart: always
      build: ./docker/web
      working_dir: ${CONTAINER_PROJECT_PATH}
      ports:
        - "3000:3000"
      volumes:
        - .:${CONTAINER_PROJECT_PATH}
        - ./node_modules:${CONTAINER_PROJECT_PATH}/node_modules
  
  # /docker/web/Dockerfile
  FROM keymetrics/pm2:latest-alpine
  FROM node:8.11.4
  
  ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
  
  RUN mkdir -p /projects/my_project
  RUN chown node:node /projects/my_project
  
  # If you are going to change WORKDIR value, 
  # please also consider to change .env file
  WORKDIR /projects/my_project
  
  USER node
  RUN npm install pm2 -g
  CMD npm install &amp;&amp; node /projects/my_project/src/index.js
  </code></pre>
  
  <p>How do I install a new module inside my container? <code>npm install</code> on host won't work because of <code>node_module</code> belongs to the <code>root</code> user. Is there any way to run it from the container?</p>
  
  <p>Edit: Is there something "one-liner" that I could run outside the container to install a module?</p>