Monday, 8 May 2017

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

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?



via Mazzy

No comments:

Post a Comment