I'm trying to set up development containers for a node.js project so that my local source files are shared with the guest (so I can dnsmasq 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:
Dockerfile:
FROM node:8
# Install app dependencies
RUN npm install -g nodemon
COPY package.json /tmp/package.json
RUN cd /tmp && npm install --production
NODE_PATH=/tmp/node_modules
WORKDIR /app
EXPOSE 8080
EXPOSE 9229
CMD nodemon --inspect index.js
docker-compose.json (truncated):
version: '3.3'
services:
app:
build: .
container_name: 'my-app'
restart: unless-stopped
ports:
- 8080:8080
- 9229:9229
volumes:
- .:/app
Because the node_modules are installed in the Dockerfile, every time I add a package to packages.json, I have to manually re-build the container:
docker-compose stop
docker-compose build
docker-compose up -d
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).
Is it possible to have this logic inside the container, and re-run npm install every time package.json is changed?