I've seen a lot of tutorials about how to build an application using docker and most of the time the Dockerfile copies package.json, package-lock.json then runs install, and finally copies the rest of the application.
Example of Dockerfile copying package.json, package-lock.json before the rest of the application
FROM node:12.18.2 as build
ARG REACT_APP_SERVICES_HOST=/services/m
WORKDIR /app
COPY ./package.json /app/package.json
COPY ./package-lock.json /app/package-lock.json
RUN yarn install
COPY . .
RUN yarn build
FROM nginx
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/build /usr/share/nginx/html
It got me triggered why this approach and not copying the entire application and then running the install. If the intention is to not copy the node_modules folder, just adding the folder at the .dockerignore file would resolve this issue. Or it is another problem that it's been prevented when doing in this order.