I have a Vue.js project that I am attempting build in Docker using the node:latest
container. Here are the relevant lines in my Makefile
that installs the packages the project requires:
CWD = $(shell pwd)
UID = $(shell id -u)
GID = $(shell id -g)
# ...
sometarget:
docker run \
--rm \
-e HOME=/home/node \
-u ${UID}:${GID} \
-v ${CWD}:/usr/src/app \
-w /usr/src/ui \
node:latest \
npm install
Note: by overriding user and group IDs, I am able to ensure that the files created by npm install
have the correct ownership, allowing the current user to run make clean
afterwards.
The npm install
invocation attempts to create ~/.npm
. However, if the current user and group ID do not match those of the node
user in the container, I end up with an error:
npm ERR! path /home/node/.npm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/home/node/.npm'
I'd like to have npm
skip the creation of /home/node/.npm
entirely, if possible. Is there a flag that prevents the creation of this directory? The container is ephemeral, so there is no value in preserving the contents of the directory.
Now you have downloaded and installed your first package! NPM creates a folder named "node_modules", where the package will be placed.
On windows I used npm list -g to find it out. By default my (global) packages were being installed to C:\Users\[Username]\AppData\Roaming\npm . Show activity on this post.
The npm clean-install command (or npm ci for short) is an in-place replacement for npm install with two major differences: It does a clean install: if the node_modules folder exists, npm deletes it and installs a fresh one. It checks for consistency: if package-lock.
From the github issue:
The short answer is no, it's not possible to bypass the CLI's cache.
Basically, npm
install is essentially:
Given that, your options likely change to:
node
user) npm install && npm cache clean
chown -R "$UID:$GID" node_modules
Another option is to mount a temp directory as the user (assume TMP_DIR was made using mktmp -d
or some sort):
-v $TMP_DIR:/home/node \
-e HOME=/home/node \
The mounted directory will exist and will be owned by the user so it'll be writable.
Yet another option (since you don't actually care about the cache directory at all) is to set HOME
to the temporary directory (which has the sticky bit set so it'll be writable by anyone:
-e HOME=/tmp \
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With