I have a docker file looks like this:
.
.
WORKING /app
COPY ..
RUN npm install
.
.
It works well but takes lots of time to be built every time (over 7 mins). After some research, I understood I have to optimize the Dockerfile so that it uses Cache. So, I've written it like this:
.
.
WORKING /app
COPY package*.json .
RUN npm install
COPY ..
.
.
Now, it builds much faster (less than 1 min). My question is "why exactly"?
If Linux can understand a file is either modified or not while copying it to either override it or read it from the cache, then I expected that both COPY ..
and COPY package*.json .
have the same behavior. Why only COPY package*.json .
uses cache?