docker-node
docker-node copied to clipboard
Cannot install packages from GitHub when mounting directory (node:12-slim)
When trying to install packages from GitHub using node:12-slim, we're seeing the following error:
npm ERR! Command failed: git clone --mirror -q git://github.com/mouse0270/bootstrap-notify.git /root/.npm/_cacache/tmp/git-clone-0decf327/.git
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-0decf327/.git'
This first broke on the morning of the 5th October. It worked fine on the morning of the 4th October.
This only happens when we're mounting a directory - if we just mount the package.json, it works fine.
I have not tried other node images.
To re-create, create a package.json in an empty directory:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"bootstrap-notify": "mouse0270/bootstrap-notify#b8d0eb0"
}
}
Create a Dockerfile alongside the package.json:
FROM node:12-slim
RUN apt-get update -qq && apt-get -qqy --no-install-recommends install git
From the directory, run:
docker build . -t test
docker run --rm -v $PWD:/blah -w /blah test npm i
That errors when trying to create leading directories:
➜ docker run --rm -v $PWD:/blah -w /blah test npm i
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm ERR! code 128
npm ERR! Command failed: git clone --mirror -q git://github.com/mouse0270/bootstrap-notify.git /root/.npm/_cacache/tmp/git-clone-11c521e0/.git
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-11c521e0/.git'
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-10-09T16_49_11_513Z-debug.log
The debug log file shows the following:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'i' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session a6eeaf780c678ebd
5 silly install runPreinstallTopLevelLifecycles
6 silly preinstall [email protected]
7 info lifecycle [email protected]~preinstall: [email protected]
8 silly install loadCurrentTree
9 silly install readLocalPackageData
10 timing stage:loadCurrentTree Completed in 5ms
11 silly install loadIdealTree
12 silly install cloneCurrentTreeToIdealTree
13 timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms
14 silly install loadShrinkwrap
15 timing stage:loadIdealTree:loadShrinkwrap Completed in 1ms
16 silly install loadAllDepsIntoIdealTree
17 info lifecycle [email protected]~prepack: [email protected]
18 info lifecycle [email protected]~postpack: [email protected]
19 silly pacote git manifest for bootstrap-notify@github:mouse0270/bootstrap-notify#b8d0eb0 fetched in 1048ms
20 silly resolveWithNewModule [email protected] checking installable status
21 timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 1054ms
22 timing stage:loadIdealTree Completed in 1056ms
23 silly currentTree [email protected]
24 silly idealTree [email protected]
24 silly idealTree `-- [email protected]
25 silly install generateActionsToTake
26 timing stage:generateActionsToTake Completed in 6ms
27 silly diffTrees action count 1
28 silly diffTrees add [email protected]
29 silly decomposeActions action count 8
30 silly decomposeActions fetch [email protected]
31 silly decomposeActions extract [email protected]
32 silly decomposeActions preinstall [email protected]
33 silly decomposeActions build [email protected]
34 silly decomposeActions install [email protected]
35 silly decomposeActions postinstall [email protected]
36 silly decomposeActions finalize [email protected]
37 silly decomposeActions refresh-package-json [email protected]
38 silly install executeActions
39 silly doSerial global-install 8
40 verbose correctMkdir /root/.npm/_locks correctMkdir not in flight; initializing
41 verbose lock using /root/.npm/_locks/staging-89c05d72a2dc0b12.lock for /blah/node_modules/.staging
42 silly doParallel extract 1
43 silly extract [email protected]
44 silly tarball no local data for bootstrap-notify@github:mouse0270/bootstrap-notify#b8d0eb0. Extracting by manifest.
45 timing audit submit Completed in 322ms
46 http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 321ms
47 timing audit body Completed in 1ms
48 timing action:extract Completed in 1024ms
49 verbose unlock done using /root/.npm/_locks/staging-89c05d72a2dc0b12.lock for /blah/node_modules/.staging
50 timing stage:rollbackFailedOptional Completed in 0ms
51 timing stage:runTopLevelLifecycles Completed in 2137ms
52 silly saveTree [email protected]
52 silly saveTree `-- [email protected]
53 warn [email protected] No description
54 warn [email protected] No repository field.
55 verbose stack Error: Command failed: git clone --mirror -q git://github.com/mouse0270/bootstrap-notify.git /root/.npm/_cacache/tmp/git-clone-ee38da5f/.git
55 verbose stack fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-ee38da5f/.git'
55 verbose stack
55 verbose stack at ChildProcess.exithandler (child_process.js:295:12)
55 verbose stack at ChildProcess.emit (events.js:210:5)
55 verbose stack at maybeClose (internal/child_process.js:1021:16)
55 verbose stack at Socket.<anonymous> (internal/child_process.js:430:11)
55 verbose stack at Socket.emit (events.js:210:5)
55 verbose stack at Pipe.<anonymous> (net.js:658:12)
56 verbose cwd /blah
57 verbose Linux 5.0.0-29-generic
58 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "i"
59 verbose node v12.11.1
60 verbose npm v6.11.3
61 error code 128
62 error Command failed: git clone --mirror -q git://github.com/mouse0270/bootstrap-notify.git /root/.npm/_cacache/tmp/git-clone-ee38da5f/.git
62 error fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-ee38da5f/.git'
63 verbose exit [ 1, true ]
When mounting just the package.json, it works fine, e.g:
➜ docker run --rm -v $PWD/package.json:/blah/package.json -w /blah test npm i
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
added 1 package from 1 contributor and audited 1 package in 1.949s
found 0 vulnerabilities
Let me know if you need any more information.
Thanks!
Trying to do npm install as root in a mounted folder caused a lot of problems. Can you check what thw permissions of your $PWD are?
Interesting - when I run npm i in the container as the node user, the package installs fine.
The files are owned by the node user (in the container) regardless of whether I run the container as root or node:

We haven't changed anything from our side, and we didn't used to have any issues. I am unsure what the root cause of the problem is, and why we're seeing this error (especially the difference between mounting a file vs directory).
Is running npm i as root something which we shouldn't be able to do?
You can do it but it does lead to all sort of permission mismatch which makes debugging these types of issue very hard.
I should also point out that it's especially problematic with mounted volumes from the host system.
I've encountered the same problem when upgrading our docker-images from node 11 to 12.
First I tried 12.13.0-alpine, then 12.13.0-buster-slim and 12.11.1-buster-slim, all with the same error.
12.9.1-buster-slim finally worked again, and so did 12.9.1-alpine. I've not checked versions in between, but somewhere there must be the problem.
I have what looks like the same issue which started sometime between 12/13 and 12/27 - using node+npm from deb.nodesource.com. It didn't matter which version of node I used (still using 8 for some builds), but it starts in npm 6.11.0 (6.10.3 works fine).
Confirming the issue. Currently using this as a workaround (thanx to @hcomnetworkers !)
FROM node:12.9.1-alpine
....
RUN npm i
....
FROM node:12-alpine
....
COPY --from=0 ...
(assumes that all node-gyp output will be compatible between different minor versions of the node container)
I believe y'all are running into this issue https://github.com/npm/cli/issues/624
A fix is in the latest release of npm https://github.com/npm/cli/releases/tag/v6.13.6
I believe y'all are running into this issue npm/cli#624
A fix is in the latest release of npm https://github.com/npm/cli/releases/tag/v6.13.6
Installing npm that includes v6.13.6 solved the issue for me. Thank you!
Just in case - for those who are on alpinelinux-based containers (comes with official docker image of node-red): as of today, container is built on alpinelinux v3.10. the fix is available only in npm v12.14.1-r0 that is not in v3.10 To get required version, one need to append "@edge http://nl.alpinelinux.org/alpine/edge/main" to /etc/apk/repositories and then install "apk add npm@edge"
Guys, I was having the same problem and maybe/probably because I am too dumb on docker I couldn't figure out how to make npm@edge version work on my docker image. Finally, I've noticed the ending sentence of @hcomnetworkers which made my day. :heart:
So, if anyone is struggling with that, simply downgrade the version of your Linux alpine image to 12.9.1-alpine as suggested above, as a workaround, and it should work at least until the image edge version changes are moved to the latest release.
chown root:root -R xxx/bin/npm or chown root:root -R /xxxx
chown root:root -R xxx/bin/npm or chown root:root -R /xxxx
Thanks mate, this answer really help me ###