Broken NPM cache folder settings do not allow running image without root
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
- #2702 de @Cdineshreddy12 — cerrado sin fusionar
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- docker, node.js
- Área
- devops, infrastructure
Línea de trabajo
Comienza inspeccionando la configuración de la imagen Docker en busca de npm_config_prefix, npm_config_userconfig, HOME y ubicaciones de caché con permisos de escritura. Reproduce el pipeline de Jenkins reportado como usuario no root y con un sistema de archivos raíz de solo lectura. Se considera terminado cuando npm ci, npm run build y npm publish funcionan sin requerir root ni una sobrescritura de caché por ejecución.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Environment
- Platform: Linux
- Docker Version: Docker Engine v29 (but can be replicated with older versions)
- Node.js Version: LTS 24 and 22 (can be replicated with all versions from v16)
- Image Tag: 22.22.2-alpine
Expected Behavior
Unmodified Node.js Docker image should be runnable without root privileges.
Current Behavior
The image is completely broken as a base build image in environments where one could not modify a running user, e.g., on Jenkins pipelines which by default run under Jenkins user and the UID is most probably not the same as UID 1000 which is used in the image. The same issue can be observed on the free GitHub Actions runners.
It is also broken as a base runtime image on read-only root filesystem environments, e.g., Kubernetes containers with readOnlyRootFilesystem: true.
The source of these issues is that npm_config_prefix is set to /usr/local and npm_config_userconfig is not set at all, so NPM is trying to use HOME folder which in the docker image is set to /. That folder is not writable by any of the users except root.
The only workaround on Jenkins is to set NPM_CONFIG_CACHE to something like /tmp/jenkins/.npm. GitLab/GitHub runners can be fixed in similar manner.
Possible Solution
The real fix should be to create .npm cache folder somewhere writable by any user on the docker image, so at least it works by default on CI pipelines. Maybe create some kind of documented folder specified via npm_config_userconfig so anyone can map it and modify the behaviour of a running user.
Steps to Reproduce
Create a Jenkins pipeline for any Node.js project using NPM and try to build it:
pipeline {
agent {
docker {
image 'node:22.22.2'
}
}
stages {
stage('Build and publish') {
steps {
sh "npm ci"
sh "npm run build"
sh "npm publish"
}
}
}
}
12:51:45 npm error code EACCES
12:51:45 npm error syscall mkdir
12:51:45 npm error path /.npm
12:51:45 npm error errno EACCES
12:51:45 npm error
12:51:45 npm error Your cache folder contains root-owned files, due to a bug in
12:51:45 npm error previous versions of npm which has since been addressed.
12:51:45 npm error
12:51:45 npm error To permanently fix this problem, please run:
12:51:45 npm error sudo chown -R 1002:1002 "/.npm"
Additional Information
I chose Jenkins as an example. The same issue can be reproduced in any CI/CD environment which doesn't run under root user: rootless Docker, GitHub Actions, etc.
As evident from the past, considering cryptic and sometimes incorrect error messages coming from NPM, people constantly struggle to understand why it doesn't work for them in one way or another:
https://github.com/nodejs/docker-node/issues/1734
https://github.com/npm/cli/issues/3910
I know that there are some practices documented how to run this image without a root user, but that's not the point of this ticket. It can be fixed at the source of this image without the need to use all those workarounds.
- Lenguaje dominante
- Dockerfile
- Estrellas
- 8.6k
- Forks
- 2k
- Merge medio
- 1 d 3 h
- PR fusionados (30 d)
- 25
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nodejs/docker-node
-
alpine build process
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
nodejs/docker-node#2707 ·
Los mantenedores suelen responder en 1 día
-
build process
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
nodejs/docker-node#2671 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
nodejs/docker-node#1779 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
nodejs/docker-node#1707 · 3 comentarios · 7 reacciones ·
Los mantenedores suelen responder en 1 día
-
docs
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
nodejs/docker-node#1101 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de nodejs/docker-node
Issues similares
-
Adopt pr-gate v3.3.0Abiertoarea: ci enhancement perceived difficulty: 1
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Nitjsefnie-Harness-Commons/daedalus#1859 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
perfectra1n/triliumnext-mcp#150 ·
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
Integration tests: each test waits about 50 seconds in Azure SDK retries while Azurite startsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Lambda Web Function AvailabilityAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
cdklabs/cdk-nextjs#365 ·
Los mantenedores suelen responder en 1 día