When NPM START needs write permission?

38 Views Asked by At

I have a simple NestJS application. I'm creating its docker image.

//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"]

After building the image. I can run the image locally. I use this on AWS ECR also with ECS. For that we have CI/CD build on AWS. However sometimes when I restart the ECS service, it fails with error:

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

Looking at the error, I understand 2 things:

  1. When starting the application with npm start, npm is trying to write something and only sometimes. But since it is in read-only mode, it is failing.
  2. If I give it write permission it will work.

I have 2 question regarding it:

  1. What I don't understand is why npm sometimes needs write permission. It happens sometimes only.
  2. How can i reproduce this issue locally ? When I build and run the image locally with --read-only, I'm not getting error 99% of time.
0

There are 0 best solutions below