Closed hata6502 closed 1 year ago
This problem seems to be due to npm v7 and v8.
The behavior of npm run
with root, is changed between npm v6 and v7.
When git clone https://github.com/hata6502/node-docker-test.git
is executed by Ubuntu desktop user,
the UID is almost 1000.
node-docker-test
directory is owned by node
user on Docker because node
's UID is also 1000.
So, npm-scripts is executed by the working-directory owner: node
.
This behavior may be difficult for Ubuntu Desktop user.
I resolved it by sudo chown -R root:root node-docker-test/
, but is it the correctly solution?
I'm not sure why I just ran into this because I'm pretty sure I had been using node 16, but I think the documentation should probably suggest that starting docker with -u node:node
or -u 1000:1000
is appropriate because node will change its user to node
even if ran as root in a root container.
i'm having the same problem, running docker run node npm i
with a "preinstall": "npx npm-force-resolutions"
etc in scripts fails either with:
docker run node npm i
(clickme)= output of docker run node whoami
root
= output of docker run node npx -c whoami
node
docker run npm config ls -l
shows that the default no .npmrc
is never overridden for th enode
user (clickme)node
user, indeed, runs in the in the root
users envdocker run node sh -c 'find ~'
> ```
> /root
> /root/.bashrc
> /root/.profile
> /root/.gnupg
> /root/.gnupg/random_seed
> /root/.gnupg/pubring.kbx
> /root/.gnupg/private-keys-v1.d
> /root/.gnupg/crls.d
> /root/.gnupg/crls.d/DIR.txt
> /root/.gnupg/pubring.kbx~
> /root/.gnupg/trustdb.gpg
> /root/.npm
> /root/.npm/_logs
> /root/.npm/_logs/2022-03-02T09_59_07_157Z-debug-0.log
> ```
> (note: no `.npmrc` here either)
= output of docker run node npx -c 'find ~'
> ```
> /root
> find: '/root': Permission denied
> ```
= output of docker run node npx -c 'find /home/node'
> ```
> /home/node
> /home/node/.bashrc
> /home/node/.profile
> /home/node/.bash_logout
> ```
= output of docker run node npx -c 'env | sort'
> ```
> COLOR=1
> EDITOR=vi
> HOME=/root
> HOSTNAME=63da0c0a688b
> INIT_CWD=/opt/project
> NODE=/usr/local/bin/node
> NODE_VERSION=17.6.0
> PATH=/opt/project/node_modules/.bin:/opt/node_modules/.bin:/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
> PWD=/opt/project
> TERM=xterm
> YARN_VERSION=1.22.17
> npm_command=exec
> npm_config_cache=/root/.npm
> npm_config_call=env | sort
> npm_config_global_prefix=/usr/local
> npm_config_globalconfig=/usr/local/etc/npmrc
> npm_config_init_module=/root/.npm-init.js
> npm_config_local_prefix=/opt/project
> npm_config_metrics_registry=https://registry.npmjs.org/
> npm_config_node_gyp=/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js
> npm_config_noproxy=
> npm_config_prefix=/usr/local
> npm_config_user_agent=npm/8.5.1 node/v17.6.0 linux x64 workspaces/false
> npm_config_userconfig=/root/.npmrc
> npm_execpath=/usr/local/lib/node_modules/npm/bin/npx-cli.js
> npm_lifecycle_event=npx
> npm_lifecycle_script=env | sort
> npm_node_execpath=/usr/local/bin/node
> npm_package_json=/opt/project/package.json
> npm_package_name=node-project
> npm_package_version=1.0.0
> ```
(logs from on :latest
, tested also on :slim
,:bullseye
,:buster
,:alpine
,:lts
,:10
,:14
... etc)
I am having this same problem as rood and a "node" user and regardless of whether npm is therefore trying to write to /tmp/npm_cache or /home/node/.npm/_cacache/tmp
This issue is resolved by installing npm v9 🎉 https://github.blog/changelog/2022-10-24-npm-v9-0-0-released/
We believe the changes made lay the ground-work for future improvements to the default npm experience long-term. Notably, Docker users should find this release to to be beneficial as we simplifie file permissions
Environment
node:16
Expected Behavior
When execute
npm run
by root user, the npm-script is also executed by root. It is the behavior of Node 14.Current Behavior
When execute
npm run
by root user, the npm-script is executed bynode
user.Steps to Reproduce
Clone the example repository.
Then, run the following
docker run
command.Result
The npm-script is executed successfully on Node 14, but a permission error is occured on Node 16.
Show the detail of process by
ps -au
.Result
The npm-script is executed by root user on Node 14, but it is executed by
node
user on Node 16.Additional Information
This problem may be not reproduced on Docker Desktop for Mac.