我有一个简单的 NestJS 应用程序。我正在创建它的 docker 镜像。
//Content of 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 会尝试写一些东西,但只是有时。但由于它处于只读模式,所以失败了。我有两个问题:
--read-only
在本地构建并运行图像时,99% 的时间都不会出现错误。Npm 检查版本更新并更新缓存。您可以使用
—update-notifier false
标志禁用此行为。
https://docs.npmjs.com/cli/v10/using-npm/config#update-notifier
看起来
update-notifier
默认情况下每周检查更新。
https://github.com/npm/cli/blob/latest/lib/cli/update-notifier.js