I'm trying the tutorial on how to dockerize a nodejs application here: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
What I don't understand is why we don't take this docker file
FROM node:14
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]
And simplify it to:
FROM node:14
WORKDIR /usr/src/app
COPY . .
RUN npm install
EXPOSE 8080
CMD [ "node", "server.js" ]
That is, why do we have to copy all the files after the npm install? Why not do it before since it will already include the package*.json
?