node-docker-good-defaults icon indicating copy to clipboard operation
node-docker-good-defaults copied to clipboard

EACCESS on `docker-compose exec node npm i <package>`

Open snowbytes opened this issue 4 years ago • 1 comments

First of all, a huge thank you (and all the contributors) for this knowledge nugget of a repo. Being a beginner to containers, it was a blast to go through the files.

I am getting a EACCESS error when trying to install a package using the standard dce node npm i <package> image

AFAIU, the error comes from a volume ownership issue when operating as non root, since the excluded node_modules (via volume mount) is root owned by default, blocking writes and forcing dep installs with dce -w <parentDir> npm i <package> : image

It turns out there's a simplified version of this workaround to the volume problem. By creating the target node_modules as a non root user on build time, the ownership stays the same when the volume is mounted. Besides resolving my issue and simplifying the installation command, this has the added benefits of having 1 package* file in the container, and avoiding issues related to file bind mounts (see #28).

If this is to your liking, I am willing (and happy :smile: ) to make PR with the fix. Thanks for your work!

snowbytes avatar Jun 22 '21 20:06 snowbytes

I'm happy to review a PR. It sounds like that would just be a change to line 21 to RUN mkdir -p /opt/node_app/node_modules && chown node:node /opt/node_app?

Also, feel free to create a 2nd PR for updating the package-lock.json.

Thanks!

BretFisher avatar Jul 02 '21 23:07 BretFisher

Now that I'm re-reading this a year later, it seems that the problem is the original command is using the wrong location for node_modules, and should be:

docker compose exec -w /opt/node_app node npm install --save <package>

A few of the examples on how to install npm packages were incomplete, and left off the -w to change the workdir for where npm should install packages (which is in the parent directory of the app). I've updated inline docs, and readme examples.

BretFisher avatar Sep 19 '22 21:09 BretFisher