docker: having trouble running npm install after creating a new user

巧了我就是萌 提交于 2019-12-03 07:03:36

so it turns out that this may be an issue with docker.

was able to get around this by switching from USER nonroot to RUN /bin/su nonroot instead, afterwards everything worked fine.

I was getting the similar mistakes when trying to create any yeoman project and finnally found the solution :)

I was getting that error because the owner of .npm folder in my home directory was "root" user so I used

sudo chown [username] .npm

and now I can use Yeoman and npm without errors :)

Hope it helps!

I have a couple of suggestions for modifications/suggestions:

  • Cache your node modules earlier in the Dockerfile using something like this (put this right after the apt-get:

    ADD package.json /tmp/package.json
    RUN cd /tmp && npm install
    RUN mkdir -p /src && cp -a /tmp/node_modules /src
    

    This way if your application code changes you aren't rebuilding all your node modules each time. Put this before your ADD . /src. More details/examples are available in my blog post article.

  • You shouldn't need to worry about running things as root in your Dockerfile... that is the default. Perhaps your problem isn't related to root but to the content inside your host's directory. Do you maybe need to clean out a lockfile from your code's dir?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!