Docker Community Forums

Share and learn in the Docker community.

EACCES: permission denied, open '/usr/local/lib/node_modules/npm/bin/npm-cli.js'

Hello sir i am new to docker, i am using ubuntu budgie(linux) 20.04 my docker version is
Docker version 18.09.9, build 1752eb3
i have install docker using snap package manager and the path is like this
/snap/bin/docker.machine /snap/bin/docker.compose /snap/bin/docker /snap/bin/docker.help
I have install nodejs and npm in my host machine form this link
nodejs install link
I am learning docker by making a single nodejs express app with docker. Here is my Dockerfile

FROM node:lts
USER node
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
WORKDIR /home/node
COPY package.json .
RUN npm install
COPY . .
CMD ['npm', 'start']

here is my app.js file

const express = require('express');
const app = express()

app.get('/', (req, res) => {
  res.send('hello world')
})

app.listen(3000, () => {
  console.log('app is renning at 3000');
})

When i start to build an image from this dockerfile i get this error

internal/fs/utils.js:230
    throw err;
    ^

Error: EACCES: permission denied, open '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
    at Object.openSync (fs.js:458:3)
    at Object.readFileSync (fs.js:360:35)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1152:22)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  errno: -13,
  syscall: 'open',
  code: 'EACCES',
  path: '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
}
The command '/bin/sh -c npm install --only=prod' returned a non-zero code: 1

Please tell me how can i fix this.
Thanks.

1 Like

Well first I’d ceck if the npm-cli.js is really present and accessible by user: node.
So run the container and log-into it afterwards:

docker exec -it < id of container > /bin/bash

now check the permissions