Skip to content

Instantly share code, notes, and snippets.

@kandros
Last active December 17, 2020 09:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kandros/81285a5c343bd0b5017c2cbdddb4c112 to your computer and use it in GitHub Desktop.
Save kandros/81285a5c343bd0b5017c2cbdddb4c112 to your computer and use it in GitHub Desktop.
Dockerfile for next.js projects
e2e
fixtures
*.test.*
node_modules
.next
.env
Dockerfile
.git
FROM node:15.3.0-alpine3.10 as deps
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn --production --silent
RUN cp -R node_modules /tmp/prod_node_modules
RUN yarn
FROM deps as builder
WORKDIR /app
COPY . .
ENV NODE_ENV=production
RUN yarn build
FROM node:15.3.0-alpine3.10 AS release
ENV NODE_ENV=production
WORKDIR /app
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /tmp/prod_node_modules ./node_modules
COPY --from=builder /app/.env.production ./.env.production
COPY --from=builder /app/package.json ./package.json
EXPOSE 3000
CMD ["npm", "start"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment