Docker build is not using cache all the time for react/node project


This Content is from Stack Overflow. Question asked by suvodipMondal

I have a docker file for deploying my react project. Here is the dockerfile:

FROM node:14.2.0

COPY package.json /tmp/package.json
RUN cd /tmp && npm install --silent
RUN mkdir -p /home/node/app/ && cp -a /tmp/node_modules /home/node/app/

WORKDIR /home/node/app/
USER root
COPY . ./

I believe if there is no change in package.json it will use cache for npm install(2nd step) and copying node_modules (3rd step).

But even if there is no change in package.json it does not.
How do I cache the steps then ?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?