为什么我在 Gitlab CI/CD 管道上的 Docker 中收到"不允许跨设备链接"错误?



我尝试删除node_modules文件夹,但仍然收到错误。它工作得很好,但突然出现了这个错误。

如果有帮助的话,这是一个react应用程序。

Docker文件

## Stage 0, "builder", based on Node.js, to build and compile the frontend
# base image
FROM node:alpine as builder
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
## add app
COPY . /app
# delete node modules to fix discrepancies
RUN rm -rf node_modules/
#RUN npm install && npm audit fix && npm audit fix --force && npm install
RUN npm install -g npm@7.0.3 && npm install && npm audit fix
RUN npm run build 
## Stage 1, "deployer", use nginx to deploy the code
## start app
FROM nginx:alpine
RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /app/build /usr/share/nginx/html/
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx-custom.conf /etc/nginx/conf.d/default.conf

控制台错误

npm notice 
npm notice New patch version of npm available! 7.0.2 -> 7.0.3
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.3>
npm notice Run `npm install -g npm@7.0.3` to update!
npm notice 
npm ERR! code EXDEV
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/npm
npm ERR! dest /usr/local/lib/node_modules/.npm-i9nnxROI
npm ERR! errno -18
npm ERR! EXDEV: cross-device link not permitted, rename '/usr/local/lib/node_modules/npm' -> '/usr/local/lib/node_modules/.npm-i9nnxROI'
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-10-23T16_47_42_554Z-debug.log
The command '/bin/sh -c npm install -g npm@7.0.3 && npm install && npm audit fix' returned a non-zero code: 238

我遇到了同样的问题。由于您的基本映像是node,因此npm应该已经全局安装。不需要运行npm install -g npm@7.0.3,并且之后仍然能够执行所有与npm相关的项。

抱歉,没有足够的代表发表评论。

事实上,我也遇到过类似的问题。Node已经更新,将npm版本提升到了7+,这似乎引起了人员问题。在我完全解决问题之前,我的解决方案是将我的Node/NPM版本锁定在我的容器构建中。

FROM node:14.14-alpine3.11是我正在使用的指令,它使我保持在6.x.x版本,以保持我的构建正常工作。

最新更新