Npm permission denied


Linux 29~20.04.1-Ubuntu, Docker version 20.10.12, build e91ed57

i run a php image and install latest nodejs v17 inside it

i enter inside my container as root with command like this :

sudo docker exec -u root -t -i 6634681df637 /bin/bash

inside my container, i enter in my /var/www folder then enter this command :

npx @vue/cli create ais-ecommerce-demo-app from the official algolia documentation Getting started with Vue InstantSearch | Algolia

here the command and error below :

npx @vue/cli create ais-ecommerce-demo-app
 ERROR  Error saving preferences: make sure you have write access to /root/.vuerc.
(EACCES: permission denied, open '/root/.vuerc')

Vue CLI v4.5.15
? Please pick a preset: Default ([Vue 2] babel, eslint)

Vue CLI v4.5.15
✨  Creating project in /var/www/ais-ecommerce-demo-app.
🗃  Initializing git repository...
⚙️  Installing CLI plugins. This might take a while...

glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'scandir',
  path: '/root/.npm/_logs'
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /root/.npm/_cacache/tmp
npm ERR! errno EACCES
npm ERR! 
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! 
npm ERR! To permanently fix this problem, please run:
npm ERR!   sudo chown -R 1000:1000 "/root/.npm"

i already tried chown, chmod 777, but i am root, why the command failed, and how to resolve this issue ?

best regards

I’m impressed by your answers, really !!!

This is a community forum, not an official paid support. People answer if they can and when they have time, because they like to help in their free time. It is more likely to get an answer, if you just ask nicely again, if someone just missed your question among many others.

When you have “permisison denied” error, you should check the permissions of that file or folder (ls -l /root/) and try to write or read that file manually with cat for example.

You can also check if you are really inside a container. Once I thought I was in a container but it turned out I failed to enter the container so I ran the commands on my host. I didn’t notice it for minutes.

An other reason could be a rootless container or enabled user namespaces when you think you are root but you are actually not root on the host, only in the container. In this case if you try to write on a bind mounted folder which is not configured to be writable from a container, you won’t be able to write it.

Other tip to get an answer more quickly. Provide as much information as you can. Including the exact steps to reproduce the issue. “I run a php image” does not tell us which image, which version or how you ran it.

I tried it with the php:8.0-fpm image and I got a different error. Actually I got multiple errors every time I ran it so it can also be a bug in the software.