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
WORKDIR $HOME/hello
RUN npm install

EXPOSE 8080

CMD ["npm", "start"]

which it used to build my application from docker-compose

  • Dockerfile php-fpm unmet dependencies
  • Docker Swarm on native hosts
  • What is wrong in my docker-compose.yml file?
  • Docker volume on external hard drive
  • Image push docker Registry Fails
  • Docker not found when building docker image using Docker Jenkins container pipeline
  • version: '2'
    services:
      hello:
        build: ./hello
        command: "pm2-docker server.js"
        ports:
          - 8080:8080
        volumes:
          - ./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 : How to run a service and a terminal in one command?
  • Meteor Spawn Error ENOENT
  • What is the essential difference between docker and rkt?
  • Docker: how to build an image from a non-master branch on Github repository
  • Docker image for aspNet core hangs on windows
  • How do I add big HTTP files in a Dockerfile and exclude them from image layers?
  • 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.