You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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偶尔会尝试写入内容,但因文件系统只读而失败;
  • 赋予写入权限即可解决问题。

我的疑问:

  1. 为何npm start仅偶尔需要写入权限?
  2. 如何在本地复现该问题?本地使用--read-only参数构建并运行镜像时,99%的情况下不会报错。

内容的提问来源于stack exchange,提问作者Shadab Faiz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 23:25:15