-
Notifications
You must be signed in to change notification settings - Fork 2k
fails to invoke npm when used in run-scripts #1734
Copy link
Copy link
Open
Description
Environment
- Platform: MacOS
- Docker Version: 20.10.16
- Node.js Version: 16.15.1
- Image Tag: node:16.15.1-alpine
Expected Behavior
Given the following package.json
{
"name": "test",
"scripts": {
"ver": "npm --version"
},
"devDependencies": {
"cowsay": "^1.5.0"
}
}$ npm run ver
> ver
> npm --version
8.12.1The same behavior should be replicated within a container runtime
Current Behavior
When running within a container runtime, npm fails and returns 243 exit code
$ docker run --rm -v $PWD:/app --workdir /app --entrypoint npm node:16.15.1-alpine run ver
> ver
> npm --version
npm notice
npm notice New minor version of npm available! 8.11.0 -> 8.12.1
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.12.1>
npm notice Run `npm install -g [email protected]` to update!
npm notice
$ echo $?
243When using a different image, it works as expected
$ docker run --rm -v $PWD:/app --workdir /app --entrypoint npm node:14-alpine run ver
> test@ ver /app
> npm --version
6.14.17It works on on some images (note the --user node:node option)
$ docker run --rm -v $PWD:/app --workdir /app --entrypoint npm node:16.15.0-alpine3.15@sha256:bb776153f81d6e931211e3cadd7eef92c811e7086993b685d1f40242d486b9bb run ver
> ver
> npm --version
8.5.5
npm notice
npm notice New minor version of npm available! 8.5.5 -> 8.12.1
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.12.1>
npm notice Run `npm install -g [email protected]` to update!
npm notice
$ docker run --rm -v $PWD:/app --workdir /app --entrypoint npm --user node:node node:18-alpine run ver
> ver
> npm --version
8.11.0when the node user is used, then there a permission issue when mount volumes are used.
$ docker run --rm -it -v $PWD:/src -v node_modules:/src/node_modules --workdir /src --user node:node --entrypoint /bin/sh node:lts-alpine -c 'npm install && npm run ver'
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /src/node_modules/ansi-regex
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/src/node_modules/ansi-regex'
npm ERR! [Error: EACCES: permission denied, mkdir '/src/node_modules/ansi-regex'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/src/node_modules/ansi-regex'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/node/.npm/_logs/2022-06-09T07_10_27_665Z-debug-0.log
$ docker run --rm -it -v $PWD:/src -v node_modules:/src/node_modules --workdir /src --user root:root --entrypoint /bin/sh node:lts-alpine -c 'npm install && npm run ver'
added 41 packages, and audited 42 packages in 2s
3 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.11.0 -> 8.12.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.12.1
npm notice Run npm install -g [email protected] to update!
npm notice
> ver
> npm --version
Steps to Reproduce
Use the package.json configuration above and repeat the commands in this post.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels