You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
899B

  1. # Install dependencies only when needed
  2. FROM node:lts-alpine AS deps
  3. WORKDIR /opt/app
  4. COPY package.json package-lock.json ./
  5. RUN npm install --frozen-lockfile
  6. # Rebuild the source code only when needed
  7. # This is where because may be the case that you would try
  8. # to build the app based on some `X_TAG` in my case (Git commit hash)
  9. # but the code hasn't changed.
  10. FROM node:lts-alpine AS builder
  11. ENV NODE_ENV=production
  12. WORKDIR /opt/app
  13. COPY . .
  14. COPY --from=deps /opt/app/node_modules ./node_modules
  15. RUN npm run build
  16. # Production image, copy all the files and run next
  17. FROM node:lts-alpine AS runner
  18. EXPOSE 3000
  19. ARG X_TAG
  20. WORKDIR /opt/app
  21. ENV NODE_ENV=production
  22. COPY --from=builder /opt/app/next.config.js ./
  23. COPY --from=builder /opt/app/public ./public
  24. COPY --from=builder /opt/app/.next ./.next
  25. COPY --from=builder /opt/app/node_modules ./node_modules
  26. CMD ["node_modules/.bin/next", "start"]