运行 npm install in alpine-chrome docker 图像的权限被拒绝
Permission denied to run npm install in alpine-chrome docker image
我正在尝试在 alpin-chrome (86-with-node) 上创建我自己的 docker 图像,以便将我的 nodejs 应用程序与 puppeteer 一起使用。
谁能告诉我为什么我无法访问 app 目录来安装 npm 包?使用默认的 alpine 安装 npm 包就像一个魅力...
我试过以下docker文件:
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.
在此处尝试官方帮助文档 https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally 看看是否可以解决问题。
如果您从缓存中构建图像,请尝试使用 --no cache 作为参数进行 docker 构建以获得干净的构建。
尝试使用root用户
FROM zenika/alpine-chrome:86-with-node
USER root
我正在尝试在 alpin-chrome (86-with-node) 上创建我自己的 docker 图像,以便将我的 nodejs 应用程序与 puppeteer 一起使用。
谁能告诉我为什么我无法访问 app 目录来安装 npm 包?使用默认的 alpine 安装 npm 包就像一个魅力...
我试过以下docker文件:
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.
在此处尝试官方帮助文档 https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally 看看是否可以解决问题。
如果您从缓存中构建图像,请尝试使用 --no cache 作为参数进行 docker 构建以获得干净的构建。
尝试使用root用户
FROM zenika/alpine-chrome:86-with-node
USER root