Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Dockerfile to multi-stage version #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Use the official lightweight Node.js 18 image.
# https://hub.docker.com/_/node
FROM node:18-slim
FROM node:22.2.0-slim as BUILD_STAGE

# Create and change to the app directory.
WORKDIR /usr/src/app
WORKDIR /app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
COPY package*.json ./
COPY package.json yarn.lock ./

# Install all dependencies.
RUN npm install
RUN yarn install --frozen-lockfile

# Copy local code to the container image.
COPY . .

# Build the app
RUN npm run build
RUN yarn build

# Run the web service on container startup.
CMD [ "npm", "start" ]
FROM node:alpine

WORKDIR /app

COPY --from=BUILD_STAGE /app/package.json ./package.json
COPY --from=BUILD_STAGE /app/node_modules ./node_modules
COPY --from=BUILD_STAGE /app/.next ./.next
COPY --from=BUILD_STAGE /app/public ./public

EXPOSE 3000

CMD ["yarn", "start"]