It's very good question. Docker creates layers for each command COPY/ADD (and some others, you need to read documentation). In build time docker will see to the changes, if in some layer will detected change all below layers will be rebuild.
For example, assume we have like this Dockerfile:
WORKDIR /app
COPY . /app
RUN npm install
And we will change source code very frequently, then docker will execute npm install for each change. It's very bad and not efficient. Because for each little change you will reinstall whole nodejs packages (and if you not using volume or cache it will take loooong time).
I'll try answer with my bad english :)
It's very good question. Docker creates layers for each command COPY/ADD (and some others, you need to read documentation). In build time docker will see to the changes, if in some layer will detected change all below layers will be rebuild.
For example, assume we have like this Dockerfile:
And we will change source code very frequently, then docker will execute
npm install
for each change. It's very bad and not efficient. Because for each little change you will reinstall whole nodejs packages (and if you not using volume or cache it will take loooong time).In this case:
we will execute
npm install
only when package.json changes (some package added or removed so on).Great explanation. I too had the same question.
right on :)
Thank you for the detailed response! Your English are perfect btw.
The best explanation so far. Much better than 99% of the youtubers/tutorials online ! Thanks Raimbek ! This is awesome
Thank you! i was looking for this answer too