Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.js image on Alpine 3.16 doesn't work since 18.6.0 update #1749

Closed
KMatuszak opened this issue Jul 15, 2022 · 14 comments
Closed

Node.js image on Alpine 3.16 doesn't work since 18.6.0 update #1749

KMatuszak opened this issue Jul 15, 2022 · 14 comments

Comments

@KMatuszak
Copy link

KMatuszak commented Jul 15, 2022

Environment

  • Platform: Ubuntu 20.04.4 LTS x86_64
  • Docker Version: Docker version 20.10.17, build 100c701
  • Node.js Version: 18.6.0
  • Image Tag: 18.6.0-alpine3.16

Expected Behavior

App should start normally, as it was on 18.5.0-alpine3.16.

Current Behavior

Container is restarting with this output:

npm ERR! code EROFS
npm ERR! syscall open
npm ERR! path /tmp/start65788697724.sh
npm ERR! errno -30
npm ERR! rofs EROFS: read-only file system, open '/tmp/start65788697724.sh'
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

When I start it without --read-only flag, the same happens, but it says only sh: /tmp/start6578863454.sh: Permission denied.

Steps to Reproduce

  • Build container using simple Dockerfile:
FROM node:18.6.0-alpine3.16
WORKDIR /app
COPY . .
RUN ["npm", "i"]
ENTRYPOINT ["npm", "start"] # Same happens with CMD
  • Start it:
docker run --name app --read-only --restart unless-stopped -d image
# or without read-only
docker run --name app --restart unless-stopped -d image
  • See the logs:
docker logs app
@vashian
Copy link

vashian commented Jul 25, 2022

Environment

  • Platform: Ubuntu 20.04.4 LTS x86_64
  • Docker Version: Docker version 20.10.17, build 100c701
  • Node.js Version: 18.6.0
  • Image Tag: 18.6.0-alpine3.16

Expected Behavior

App should start normally, as it was on 18.5.0-alpine3.16.

Current Behavior

Container is restarting with this output:

npm ERR! code EROFS
npm ERR! syscall open
npm ERR! path /tmp/start65788697724.sh
npm ERR! errno -30
npm ERR! rofs EROFS: read-only file system, open '/tmp/start65788697724.sh'
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

When I start it without --read-only flag, the same happens, but it says only sh: /tmp/start6578863454.sh: Permission denied.

Steps to Reproduce

  • Build container using simple Dockerfile:
FROM node:18.6.0-alpine3.16
WORKDIR /app
COPY . .
RUN ["npm", "i"]
ENTRYPOINT ["npm", "start"] # Same happens with CMD
  • Start it:
docker run --name app --read-only --restart unless-stopped -d image
# or without read-only
docker run --name app --restart unless-stopped -d image
  • See the logs:
docker logs app

I’m dealing with the same problem as you, but I'm using node18-bullseye
I have to start my app READ-ONLY.
What is the state of this issue?

@KMatuszak
Copy link
Author

I "fixed" this by downgrading NPM in Dockerfile:

RUN ["npm", "i", "npm@8.12", "-g"]

@nicballesteros
Copy link

nicballesteros commented Aug 17, 2022

I have recently run into this issue today because the node 16 images just updated from 16.16 to 16.17 as of yesterday (Aug 16, 2022). This version of node has updated npm 8.11.0 to npm 8.15.0 which has this exact issue. I was ready to open an issue on the npm/cli repository when before hitting submit I added RUN npm install npm@8.17.0 -E --location=global before my CMD npm start line in my Dockerfile. Doing this actually fixed the EROFS issues I was having that are also mentioned in this thread. So the solution is just to sit on our hands for a new minor version of Node to come out that has npm 8.17.0 or higher packaged with it.

A consideration is that I am using the --offline and --logs-max=0 flags in read-only fs mode to silence other npm errors.
Also I can confirm that npm 8.11.0 was working for me yesterday.

@rene-leanix
Copy link

In our case, executing a command via npx, which is an alias for npm exec failed with the same error message. I tried to change the global prefix path to a location with write permissions with npm config --global set prefix ..., but even this very command failed with the same error.

In the end, the workaround was to execute the command directly in ./node_modules/.bin. You could do the same for the command(s) executed in your npm start script.

@rene-leanix
Copy link

A colleague just pointed out that the proper fix for this is to set npm_config_cache to a writable directory, e.g., ENV npm_config_cache /tmp/npm. (See this NPM issue.)

This would probably also fix #1734 and #740, both of which already suggest to set npm_config_cache.

@bobbylkchao
Copy link

@rene-leanix thanks, fix our issue as well! 👍

@ShadabFaiz
Copy link

ShadabFaiz commented Feb 19, 2024

I have a docker image of my application that was running fine til a few days ago. Now it is giving the same error. Same image was working fine till a few days ago. None of the solution works other than creating a new image

@LaurentGoderre
Copy link
Member

@ShadabFaiz are you using the 18-alpine tag? If so, 2 months ago, the alpine version that alpine points to was changed from 3.18 to 3.19 which could have cause a change in behavior.

@LaurentGoderre
Copy link
Member

Should we close this? Alpine 3.16 hasn't been supported for almost a year

@KMatuszak
Copy link
Author

This still happens on any version newer than the mentioned in this issue.

@ShadabFaiz
Copy link

@ShadabFaiz are you using the 18-alpine tag? If so, 2 months ago, the alpine version that alpine points to was changed from 3.18 to 3.19 which could have cause a change in behavior.

yes. I'm using 18-alpine tag. However, there are 2 confusing parts here.

  1. Even if the Alpine version was updated 2 months ago, I'm just running the same image that was created in early January, not building a new image. Shouldn't it work like previously?
  2. Our other applications are also using the same tag, and none of them have this issue.

Also, when does npm decide it needs to write to the cache?

@LaurentGoderre
Copy link
Member

The fixed mentioned above does work

Before:

docker run --rm -it --read-only --entrypoint npm node:18-alpine ping --loglevel=verbose

npm verb cli /usr/local/bin/node /usr/local/bin/npm
npm info using npm@10.2.4
npm info using node@v18.19.1
npm verb title npm ping
npm verb argv "ping" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:/root/.npm/_logs/2024-02-20T15_08_46_284Z-
npm verb logfile could not be created: Error: EROFS: read-only file system, open '/root/.npm/_logs/2024-02-20T15_08_46_284Z-debug-0.log'
npm verb logfile no logfile created
npm notice PING https://registry.npmjs.org/
npm verb stack Error: ENOENT: no such file or directory, mkdir '/root/.npm/_cacache'
npm verb cwd /
npm verb Linux 6.6.16-linuxkit
npm verb node v18.19.1
npm verb npm  v10.2.4
npm ERR! code ENOENT
npm ERR! syscall mkdir
npm ERR! path /root/.npm/_cacache
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, mkdir '/root/.npm/_cacache'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 
npm verb exit -2
npm verb unfinished npm timer command:ping 1708441726318
npm verb code -2

After:

docker run --rm -it --read-only --entrypoint npm -e npm_config_cache=/tmp/npm -v npm_cache:/tmp/npm node:18-alpine ping --loglevel=verbose

npm verb cli /usr/local/bin/node /usr/local/bin/npm
npm info using npm@10.2.4
npm info using node@v18.19.1
npm verb title npm ping
npm verb argv "ping" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:/tmp/npm/_logs/2024-02-20T15_09_24_406Z-
npm verb logfile /tmp/npm/_logs/2024-02-20T15_09_24_406Z-debug-0.log
npm notice PING https://registry.npmjs.org/
npm http fetch GET 200 https://registry.npmjs.org/-/ping?write=true 300ms (cache miss)
npm notice PONG 301ms
npm verb exit 0
npm info ok 

@ShadabFaiz
Copy link

for now, we decided to completely skip npm for running our apps. We are running it through node command directly.

@KMatuszak
Copy link
Author

Closing this because it's npm fault and I don't run my apps through it for a long time now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@LaurentGoderre @ShadabFaiz @nicballesteros @rene-leanix @bobbylkchao @KMatuszak @vashian and others