Created
August 23, 2022 12:37
-
-
Save codegino/b20440ae6ae6c8ef3e815d9de9912479 to your computer and use it in GitHub Desktop.
Basic NextJS Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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