Skip to content

Instantly share code, notes, and snippets.

@codegino
Created August 23, 2022 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codegino/b20440ae6ae6c8ef3e815d9de9912479 to your computer and use it in GitHub Desktop.
Save codegino/b20440ae6ae6c8ef3e815d9de9912479 to your computer and use it in GitHub Desktop.
Basic NextJS Dockerfile
# Install dependencies only when needed
FROM node:lts-alpine AS deps
WORKDIR /opt/app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# Rebuild the source code only when needed
# This is where because may be the case that you would try
# to build the app based on some `X_TAG` in my case (Git commit hash)
# but the code hasn't changed.
FROM node:lts-alpine
RUN mkdir -p /usr/src/app
ENV PORT 3000
WORKDIR /usr/src/app
COPY package.json /usr/src/app
COPY yarn.lock /usr/src/app
# Production use node instead of root
# USER node
RUN yarn install --production
COPY . /usr/src/app
RUN yarn build
EXPOSE 3000
CMD [ "yarn", "start" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment