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

  • Configure portainer with Minikube's docker
  • docker-compose volume on node_modules but is empty
  • Arch Linux, Docker “No space left on device.”
  • Docker-compose set user and group on mounted volume
  • Blocking of docker-compose up on ubuntu 16.04
  • Why am I getting a *much* worse performance with Docker Stack than Docker Compose?
  • 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 does not free disk usage on Windows 10
  • Is it possible to update Docker on CoreOS without updating fleet and etcd?
  • Logging in Docker
  • How do you manipulate tags in docker registry 2.0 and the v2 API?
  • How does Docker run a command without invoking a command shell?
  • Docker cloud repository push: access to the requested resource is not authorized on Fedora 23
  • 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.