Install node modules before copying over your working code so that node_modules are built (and cached) before you change your service code!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
|ADD package.json /tmp/package.json|
|RUN cd /tmp && npm install && \|
|mkdir -p /opt/app && cp -a /tmp/node_modules /opt/app/|
|ADD . /opt/app|
Nov 5, 2014
Apr 13, 2017
For those like myself who were initially bewildered by this, the "Build cache" section of the Dockerfile best practices doc may help fill in the gaps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
If the package.json file changes then Docker will re-run the npm install sequence... otherwise our modules are cached so we aren't rebuilding them every time we change our apps source code!