Shouldn't docker-compose up --build suffice?
Here's our Dockerfile:
FROM node:8.12.0-alpine
# Set app directory
WORKDIR /usr/src/app
# Install git in order to allow installing
# npm packages from Github
RUN set -xe \
&& apk add --no-cache git
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
# Bundle app source
COPY . .
ENV NODE_ENV development
EXPOSE 8080
CMD ["npm","start"]
And our docker-compose file:
version: '3'
services:
web:
build: .
ports:
- 8080:8080
environment:
MONGODB_URI: mongodb://admin:app@mongo:27017/app?authSource=admin
volumes:
- .:/usr/src/app
# More info on the node_modules volume at:
# http://jdlm.info/articles/2016/03/06/lessons-building-node-app-docker.html
# under "The node_modules Volume Trick"
- /usr/src/app/node_modules
# Run nodemon with legacy watch
# https://github.com/remy/nodemon#application-isnt-restarting
# Ignore public/ because generating documentation programatically
# on startup was causing an infinite loop
command: ./node_modules/.bin/nodemon --legacy-watch --inspect=0.0.0.0:5858 --ignore public/
depends_on:
- mongo
mongo:
image: mongo:4.0
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: app
volumes:
# Using a named volume because windows doesn't deal well with mounting local folders
- app-api-mongodb-storage:/data/db
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
ME_CONFIG_MONGODB_ADMINPASSWORD: app
depends_on:
- mongo
volumes:
# Database named module has to be declared globally
app-api-mongodb-storage:
From what I can tell, docker-compose down should delete the node_modules volume, because it is created by docker-compose up.
Is there some kind of caching that is preventing package.json from being refreshed unless docker-compose --build is used in order to explicitly rebuild the Docker image?