docker - 在 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.
解决方案
尝试使用用户root
FROM zenika/alpine-chrome:86-with-node
USER root
推荐阅读
- r - R:检查软件包的哪个分支安装了 install_git
- google-chrome - 复制谷歌表格和谷歌幻灯片的链接
- sql - 如何将动态值传递给雪花查询?
- php - Symfony 使用 Composer 安装失败(定义没有类)(cocorico app)
- haskell - 如何配置 Cabal 以构建两个可执行文件?
- swift - 在 UILabel 中插入多个图像
- python - 在python中实现留一交叉验证
- node.js - 如何使用 axios.all 捕获所有承诺?
- microsoft-graph-api - 使用 Microsoft Graph Explorer 访问报告时,同意的权限不起作用
- javascript - 如何用图像制作轮播?