title: Docker automatically rerun npm install on package.json change
body: <p>I'm trying to set up <em>development</em> containers for a node.js project so that my local source files are shared with the guest (so I can <code>dnsmasq</code> wildcard requests to a local domain over port 80, but I guess that's irrelevant to the question). When I make a change locally, the node process in the container is restarted:</p>
  
  <p><code>Dockerfile</code>:</p>
  
  <pre><code>FROM node:8
  
  # Install app dependencies
  RUN npm install -g nodemon
  COPY package.json /tmp/package.json
  RUN cd /tmp &amp;&amp; npm install --production
  
  NODE_PATH=/tmp/node_modules
  WORKDIR /app
  
  EXPOSE 8080
  EXPOSE 9229
  
  CMD nodemon --inspect index.js
  </code></pre>
  
  <p><code>docker-compose.json</code> (truncated):</p>
  
  <pre><code>version: '3.3'
  services:
      app:
          build: .
          container_name: 'my-app'
          restart: unless-stopped
          ports:
              - 8080:8080
              - 9229:9229
          volumes:
              - .:/app
  </code></pre>
  
  <p>Because the <code>node_modules</code> are installed in the <code>Dockerfile</code>, every time I add a package to <code>packages.json</code>, I have to manually re-build the container:</p>
  
  <pre><code>docker-compose stop
  docker-compose build
  docker-compose up -d
  </code></pre>
  
  <p>I could set up a watch for this using inotify, but I don't like to stop the entire stack (including other services defined there).</p>
  
  <p>Is it possible to have this logic <em>inside</em> the container, and re-run <code>npm install</code> every time <code>package.json</code> is changed?</p>