Why is every build slow?
Each instruction creates a layer. Docker reuses a cached layer when the instruction and everything before it is unchanged. Copy all your code before npm ci, and changing one line of code reinstalls every package. Copy the package files first, and code changes skip the install.
See the cache work
FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --omit=dev COPY . . ENV NODE_ENV=production EXPOSE 3000 CMD ["node", "server.js"]