Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied missing write access to /opt/app/node_modules #49

Closed
jnlsn opened this issue Dec 18, 2018 · 9 comments
Closed

Permission denied missing write access to /opt/app/node_modules #49

jnlsn opened this issue Dec 18, 2018 · 9 comments

Comments

@jnlsn
Copy link

jnlsn commented Dec 18, 2018

Following the instructions from the README, I cannot install additional Node packages with docker-compose exec node npm install --save <package name> due to write permissions of the 'node' user. If I update docker-compose.yml to set the user as 'root', I can again install pacakges. I'm not sure if this is the best way to solve the install permissions or not.

@waynehaffenden
Copy link

+1 I also have this same problem, any tips on a solution?

@aidengaripoli
Copy link
Contributor

I think setting the user as root in docker-compose.yml is fine. It allows you to install packages in development but doesn't affect production security as the Dockerfile isn't modified and the docker-stack.yml will be used instead of the compose file. This is also the way I have fixed permission based issues in development and it has worked for me. There might be a better way though.

What do you think @BretFisher?

@soqt
Copy link

soqt commented Jan 9, 2019

+666 I have the save problem. Not sure how to solve it in a production-secure way.

@BretFisher
Copy link
Owner

@aidengaripoli suggestion works great IMO. Just make sure you have CI tests that test any write permissions you might need in container at runtime so you don't get caught in prod with a container that's running under user permissions and have write problems (cache files, user uploads, etc.) that you didn't have in dev due to root user.

@BretFisher
Copy link
Owner

A few options to solve this depending on what you'd like to do, in order of my preference (feedback welcome!):

  1. Fix the permissions on node_modules so they are all installed as node user, which means moving the USER Dockerfile stanza up to before npm install. This keeps your dev and prod permissions the same without reducing security (node_modules are typically the same permissions as your app files anyway.) I like this idea so much I'm going to update the repo to use this method by default, which requires moving node_modules down a directory to ensure npm has permissions to write to the pwd of node_modules. I'll close this issue with that commit but feel free to keep commenting.
  2. Run your exec commands as root using -u root and specify the working directory to the proper /opt with: docker-compose exec -u root -w /opt/ node npm install --save <package name>
  3. Update docker-compose.yml with the user:root key to run the CMD as root for local development. I now like the above two options better.

@BretFisher BretFisher pinned this issue Feb 25, 2019
@BretFisher
Copy link
Owner

Note option 2 above has a issue with using -w in the last few versions of docker-compose so follow that bug over here: docker/compose#6528

@nielsbril
Copy link

Dependencies can be installed again, but I still get the EBUSY: resource busy or locked error on package.json and package-lock.json due to the bind mount. Is there any way to fix this?

I'm on macOS 10.14.3 with Docker 18.09.2 and Docker Compose 1.23.2.

@waynehaffenden
Copy link

I'm having the same issue as @nielsbril any update guys?

@smaven
Copy link

smaven commented Oct 22, 2020

Dependencies can be installed again, but I still get the EBUSY: resource busy or locked error on package.json and package-lock.json due to the bind mount. Is there any way to fix this?

I'm on macOS 10.14.3 with Docker 18.09.2 and Docker Compose 1.23.2.

Was getting the error with npm. Switched to using yarn and it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants