首页 > 解决方案 > 在 alpine-chrome docker 映像中运行 npm install 的权限被拒绝

问题描述

我正在尝试在 alpin-chrome(86-with-node)上创建自己的 docker 映像,以将我的 nodejs 应用程序与 puppeteer 一起使用。

谁能告诉我为什么我无权访问 app 目录来安装 npm 包?使用默认的 alpine 安装 npm 包就像一个魅力......

我尝试了以下 dockerfile:

FROM zenika/alpine-chrome:86-with-node

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true

# Create app directory
WORKDIR /usr/src/scraper

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm ci --only=production
# If you are building your code for development
# RUN npm install

# Bundle app source
COPY . .


EXPOSE 3040
CMD [ "node", "app.js" ]

但我收到以下错误:

Step 5/9 : RUN npm ci --only=production
 ---> Running in 06c02bd505ac
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/src/scraper/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/src/scraper/node_modules'
npm ERR!  [OperationalError: EACCES: permission denied, mkdir '/usr/src/scraper/node_modules'] ***
npm ERR!   cause: [Error: EACCES: permission denied, mkdir '/usr/src/scraper/node_modules'] ***
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'mkdir',
npm ERR!     path: '/usr/src/scraper/node_modules'
npm ERR!   ***,
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/src/scraper/node_modules'
npm ERR! ***
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

标签: dockerdockerfilepuppeteernpm-installalpine

解决方案


尝试使用用户root

FROM zenika/alpine-chrome:86-with-node
USER root

推荐阅读