在Dockerfile中创建一个新用户并且无法安装npm deps

时间:2017-05-08 11:28:39

标签: node.js docker docker-compose dockerfile

这是我的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"]

用于从docker-compose

构建我的应用程序
version: '2'
services:
  hello:
    build: ./hello
    command: "pm2-docker server.js"
    ports:
      - 8080:8080
    volumes:
      - ./hello:/usr/src/hello

当我尝试运行docker-compose up时,我收到以下错误:

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.

为什么以用户npm install运行app会出现以下错误?

0 个答案:

没有答案