Normally when developing, the requirements tend to be static- the package.json doesn't change, but the files do.
Docker images are made up of layers, and hence we can utilise cache to help speed up the building process.
By first copying the package.json and then do
RUN npm install -g nxRUN npm install COPY . . RUN nx build proshop-api --configuration=production
It can become 5 different layers.
So when the React application code changes, but not the requirements, Docker will use the cache of the first 3 layers and only run the 5th and 6th step, saving time when building the docker image
Normally when developing, the requirements tend to be static- the
package.json
doesn't change, but the files do.Docker images are made up of layers, and hence we can utilise cache to help speed up the building process.
By first copying the
package.json
and then doRUN npm install -g nx
RUN npm install
COPY . .
RUN nx build proshop-api --configuration=production
It can become 5 different layers. So when the React application code changes, but not the requirements, Docker will use the cache of the first 3 layers and only run the 5th and 6th step, saving time when building the docker image
More info https://levelup.gitconnected.com/easy-optimization-of-your-react-docker-image-down-to-22mb-9d9e3a06870 https://tiangolo.medium.com/react-in-docker-with-nginx-built-with-multi-stage-docker-builds-including-testing-8cc49d6ec305