Docker-node: Permission problems when trying to install package globally

Created on 31 Dec 2017  路  4Comments  路  Source: nodejs/docker-node

I have checked before writing this issue #423

We have permission troubles with building node image with grpcio.

Dockerfile looks following way:

FROM node:9.3-alpine
RUN apk update && apk add python

RUN npm install -g grpc grpcli

First, if we will not run it as root, we will get following error:

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

And if we will run as root, we will get following error in infinite(!) cycle:

gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/grpcli/node_modules/fibers/.node-gyp/9.3.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/grpcli/node_modules/fibers/.node-gyp"

Most helpful comment

Thanks. Took this advice and it worked out.

Final Dockerfile:

FROM node:9.3-alpine
RUN apk update && apk add python make g++

ENV NPM_CONFIG_PREFIX=/home/node/.npm-global

WORKDIR /app

USER node
RUN npm install -g grpcli grpc

All 4 comments

Thanks. Took this advice and it worked out.

Final Dockerfile:

FROM node:9.3-alpine
RUN apk update && apk add python make g++

ENV NPM_CONFIG_PREFIX=/home/node/.npm-global

WORKDIR /app

USER node
RUN npm install -g grpcli grpc

@tigrus I recomment to put the app in /home/node/app instead of root to avoid permission issues.

@LaurentGoderre @tigrus , i am also getting the same issue.I need to create docker image running as non root user , but not sure how to achieve that.Here is my docker file :
`FROM docker.com/node:latest as node

WORKDIR /app

COPY . .

RUN npm install

RUN npm run ng build -- --prod

stage 2 : to run application

FROM docker.com/nginx:alpine

COPY --from=node /app/dist/MyApp /usr/share/nginx/html`

Was this page helpful?
0 / 5 - 0 ratings