No access permission error with npm global install on docker image
The problem is because while NPM runs globally installed module scripts as the nobody
user, which kinds of makes sense, recent versions of NPM started setting the file permissions for node modules to root
. As a result module scripts are no longer allowed to create files and directories in their module.
See discussion in NPM issue #3849, for some references.
A simple workaround, which makes sense in a docker environment, is to set the NPM default global user back to root
, like so:
npm -g config set user root
After which you shouldn't have any more EACCES
errors.
I was able to get it working by changing the default npm-global directory.
This is my dockerfile now:
FROM node:latestUSER nodeRUN mkdir /home/node/.npm-globalENV PATH=/home/node/.npm-global/bin:$PATHENV NPM_CONFIG_PREFIX=/home/node/.npm-globalRUN npm install --quiet --no-progress -g @angular/cli@latest firebase-toolsRUN npm cache clean --force