docker-node icon indicating copy to clipboard operation
docker-node copied to clipboard

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

Open KMatuszak opened this issue 3 years ago • 12 comments

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

KMatuszak avatar Jul 15 '22 12:07 KMatuszak

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?

vashian avatar Jul 25 '22 06:07 vashian

I "fixed" this by downgrading NPM in Dockerfile:

RUN ["npm", "i", "[email protected]", "-g"]

KMatuszak avatar Jul 25 '22 11:07 KMatuszak

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 [email protected] -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.

nicballesteros avatar Aug 17 '22 18:08 nicballesteros

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 avatar Nov 30 '22 12:11 rene-leanix

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.

rene-leanix avatar Dec 08 '22 12:12 rene-leanix

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

bobbylkchao avatar Apr 26 '23 03:04 bobbylkchao

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

ShadabFaiz avatar Feb 19 '24 16:02 ShadabFaiz

@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 avatar Feb 19 '24 19:02 LaurentGoderre

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

LaurentGoderre avatar Feb 19 '24 19:02 LaurentGoderre

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

KMatuszak avatar Feb 19 '24 21:02 KMatuszak

@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?

ShadabFaiz avatar Feb 20 '24 11:02 ShadabFaiz

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 [email protected]
npm info using [email protected]
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 [email protected]
npm info using [email protected]
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 

LaurentGoderre avatar Feb 20 '24 15:02 LaurentGoderre