We use the standard practices of not including node_modules in version control. However, when moving through the CI/CD pipeline, we have to reinstall NPM dependencies in several places and it makes everything very slow.
Is there a way to somehow cache NPM dependencies with Docker? I searched Google "docker cache npm dependencies" and the first hit from 2014 yielded a dead link.
Nothing else of much value came up.
One solution is to include node_modules in version control, but I think that would be a huge mistake. I think caching the dependencies somehow would be the best option.
Here is the Dockerfile as is:
FROM node:6
COPY . . # copy all files, but node_modules does not exist ( => gitignored)
RUN npm install --no-optional --only=production > /dev/null 2>&1
RUN npm install -g bower > /dev/null 2>&1
RUN bower install --config.interactive=false --allow-root > /dev/null 2>&1
ENTRYPOINT ["/bin/bash", "/root/cdt/run.sh"]
Here is one possible solution, but I can't quite figure out how it works:
=> http://bitjudo.com/blog/2014/03/13/building-efficient-dockerfiles-node-dot-js/