Faster Next.JS docker builds with npm cache
If you have a Dockerfile which looks something like (note: likely not complete, this is a very stripped down version of our Dockerfile):
FROM node:16.19.0 as prodbuild COPY ./package*.json ./ RUN npm ci –omit=dev FROM node:16.19.0 as build COPY ./package*.json ./ # We need dev dependencies to actually do the build RUN npm ci RUN npm run web:build FROM node:16.19.0 COPY –from=prodbuild /usr/src/node_modules ./node_modules COPY –from=build /usr/src/.next .next ENTRYPOINT ["npm", "run", "start"] There are a few inefficiencies.