Create a new user in Dockerfile and fails to install npm deps

This is my Dockerfile:

FROM node:7.10.0

RUN useradd --user-group --create-home --shell /bin/false app

RUN mkdir -p /usr/src/hello
ENV HOME=/usr/src/

COPY package.json $HOME/hello/
RUN chown -R app:app $HOME/*

RUN npm install -g pm2

USER app
RUN npm install


CMD ["npm", "start"]

which it used to build my application from docker-compose

  • Accessing host machine as localhost from a Docker container when building the image
  • Difference between nodejs v0.12 and v5.x distributions
  • Ping docker containers on different hosts with ip addresses
  • How to cache package manager downloads for docker builds?
  • Create a remote private registry
  • Load generation for a Docker registry
  • version: '2'
        build: ./hello
        command: "pm2-docker server.js"
          - 8080:8080
          - ./hello:/usr/src/hello

    When I try to run docker-compose up I get the following error:

    npm ERR! Error: EACCES: permission denied, mkdir '/usr/src/.npm/hapi'
    npm ERR!  { Error: EACCES: permission denied, mkdir '/usr/src/.npm/hapi'
    npm ERR!   errno: -13,
    npm ERR!   code: 'EACCES',
    npm ERR!   syscall: 'mkdir',
    npm ERR!   path: '/usr/src/.npm/hapi',
    npm ERR!   parent: 'hello' }
    npm ERR!
    npm ERR! Please try running this command again as root/Administrator.

    Why running npm install as user app get the following error?

  • Docker - Windows containers: How to use custom paths
  • Dockerizing Flask web application that uses google oauth2
  • Configure fluentd to properly parse and ship java stacktrace,which is formatted using docker json-file logging driver,to elastic as single message
  • Docker commands succeed on running container, but fail on Dockerfile
  • create file in shared folder docker container
  • How can I create ubuntu based docker host by using docker-machine with VirtualBox?
  • One Solution collect form web for “Create a new user in Dockerfile and fails to install npm deps”

    you definitely have a permissions error with ownership on the folder… my best guess is RUN chown -R app:app $HOME/* should be RUN chown -R app:app $HOME

    no /* in there. the -R option of chown already takes care of all sub-folders.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.