Every change to the status page code reruns npm install. Measure the layers, see the cache miss, and reorder the Dockerfile so dependencies stay cached.
Read the layers of the current image:
Change one line of code: open server.js, change the default SERVICE_NAME from "Status" to "Platform Status", press Save, and rebuild. Count the CACHED lines:
Open the Dockerfile and copy package.json on its own before installing, then copy the rest:
dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]The first build after the reorder installs once more. Now change server.js again, save, rebuild, and count the CACHED lines.