title: docker: having trouble running npm install after creating a new user
body: <p>So I have another follow-up question regarding installing a node.js-based framework under Docker on CoreOS, per <a href="https://stackoverflow.com/questions/21873789/docker-installing-a-node-js-application-has-issues-since-docker-runs-as-root">this post</a>.</p>
  
  <p>So, because <code>npm</code> is finicky about installing from <code>package.json</code> via root, I've had to create a nonroot sudo user in order to install the package. This is what my <code>Dockerfile</code> currently looks like inside of our repo, building off of an ubuntu image:</p>
  
  <pre><code># Install dependencies and nodejs
  RUN apt-get update
  RUN apt-get install -y python-software-properties python g++ make
  RUN add-apt-repository ppa:chris-lea/node.js
  RUN apt-get update
  RUN apt-get install -y nodejs
  
  # Install git
  RUN apt-get install -y git
  
  # Bundle app source
  ADD . /src
  
  # Create a nonroot user, and switch to it
  RUN /usr/sbin/useradd --create-home --home-dir /usr/local/nonroot --shell /bin/bash nonroot
  RUN /usr/sbin/adduser nonroot sudo
  RUN chown -R nonroot /usr/local/
  RUN chown -R nonroot /usr/lib/
  RUN chown -R nonroot /usr/bin/
  RUN chown -R nonroot /src
  
  USER nonroot
  
  # Install app source
  RUN cd /src; npm install
  </code></pre>
  
  <p>I know that this is an inelegant way to do things, but I'm otherwise at a loss as to how to complete an npm install here. When I try the above, I get errors on all of the packages as they try to install:</p>
  
  <pre><code> Error: Attempt to unlock javascript-brunch@1.7.1, which hasn't been locked
       at unlock (/usr/lib/node_modules/npm/lib/cache.js:1304:11)
       at cb (/usr/lib/node_modules/npm/lib/cache.js:646:5)
       at /usr/lib/node_modules/npm/lib/cache.js:655:20
       at /usr/lib/node_modules/npm/lib/cache.js:1282:20
       at afterMkdir (/usr/lib/node_modules/npm/lib/cache.js:1013:14)
       at /usr/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
       at Object.oncomplete (fs.js:107:15)
   If you need help, you may report this *entire* log,
   including the npm and node versions, at:
       &lt;http://github.com/npm/npm/issues&gt;
  
   ...
  </code></pre>
  
  <p>Any thoughts as to how I should modify my Dockerfile? I can only assume that this is some permissioning issue having to do with the way that I've provisioned the <code>nonroot</code> user above that might be particular to the Docker framework; I have no problem doing this kind of thing on just a vanilla ubuntu install, albeit not from script.</p>