NPM START偶需写入权限的原因及本地复现方法咨询
NestJS Docker镜像ECS重启时的npm只读文件系统问题
我有一个简单的NestJS应用,正在为其构建Docker镜像,Dockerfile内容如下:
FROM node:18-alpine RUN apk update \ && apk upgrade \ && apk cache clean \ && apk add --no-cache openssl # Create app directory WORKDIR /app # Copy source across COPY . /app # remove existing node_modules RUN rm -rf node_modules/ # install dependencies RUN npm install --omit=dev # build app RUN npm run build # run app CMD [ "npm", "run", "start"]
镜像构建完成后可本地正常运行,同时部署在AWS ECR并通过ECS运行,配套AWS CI/CD构建流程。但偶尔重启ECS服务时会出现如下错误:
start node --require dotenv/config dist/main npm ERR! code EROFS npm ERR! syscall open npm ERR! path /root/.npm/_cacache/tmp/8491f67a npm ERR! errno -30 npm ERR! rofs EROFS: read-only file system, open '/root/.npm/_cacache/tmp/8491f67a' npm ERR! rofs Often virtualized file systems, or other file systems npm ERR! rofs that don't support symlinks, give this error. npm ERR! Log files were not written due to an error writing to the directory: /root/.npm/_logs npm ERR! You can rerun the command with --loglevel=verbose to see the logs in your terminal
我对错误的理解:
- 使用
npm start启动应用时,npm偶尔会尝试写入内容,但因文件系统只读而失败; - 赋予写入权限即可解决问题。
我的疑问:
- 为何npm start仅偶尔需要写入权限?
- 如何在本地复现该问题?本地使用
--read-only参数构建并运行镜像时,99%的情况下不会报错。
内容的提问来源于stack exchange,提问作者Shadab Faiz
相关产品推荐
相关产品推荐

