Skip to content

Commit

Permalink
feat(Dockerfile): Add multi-stage build for production deployment
Browse files Browse the repository at this point in the history
- Added a new stage "deps" to install production dependencies only
- Added a new stage "builder" to build the application
- Copied necessary files from the "builder" stage to the final image
- Exposed port 5000 for the application
- Updated CMD command to run the application

This commit introduces a multi-stage build process in the Dockerfile, which separates dependency installation and application building. This improves efficiency and reduces the size of the final Docker image.
  • Loading branch information
BillChirico committed Nov 6, 2023
1 parent 97dae34 commit 52b1b04
Showing 1 changed file with 11 additions and 33 deletions.
44 changes: 11 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
# FROM node:lts-alpine

# LABEL name="Docusaurus on docker latest-stable" \
# maintainer="VolvoxLLC <[email protected]>" \
# version="1.0.0" \
# release="latest" \
# url="https://github.com/VolvoxLLC/Volvox.Apollo.Docs" \
# summary="Volvox.Apollo Docs Docker \
# on Node 20.x, lts-alpine" \
# description="Volvox.Apollo Docs \
# on Node 20.x, lts-alpine"

# # run as our node user from base image
# # we delete the dockerfiles we don't need
# # this leaves us with a default v1 docusarus install
# # we can mount our own into the container
# USER node
# RUN mkdir ~/npm-global \
# && npm config set prefix '~/npm-global' \
# && echo 'export PATH=~/npm-global/bin:$PATH' > ~/.profile \
# && mkdir -p /home/node/docs \
# && cd /home/node/docs \
# && npm install --global docusaurus-init \
# && sh -l -c docusaurus-init

# EXPOSE 5001/tcp
# USER node
# WORKDIR /home/node/docs

# CMD ["sh", "-l", "-c", "npm run serve"]

## Base ########################################################################
# Use a larger node image to do the build for native deps (e.g., gcc, python)
FROM node:lts-alpine AS deps

WORKDIR /opt/app
# Copy package.json and package-lock.json to the working directory
COPY package.json package-lock.json ./
# Install production dependencies only
RUN npm ci --only=production

# Stage 2: Build the application
FROM node:lts-alpine AS builder

WORKDIR /opt/app
# Copy all files from the current directory to the working directory in the container
# Copy node_modules from the "deps" stage
COPY package.json package-lock.json ./
COPY --from=deps /opt/app/node_modules ./node_modules
COPY . .
# Build the application
RUN npm run build
Expand All @@ -50,5 +27,6 @@ WORKDIR /opt/app
ENV NODE_ENV=production
# Copy necessary files from the "builder" stage
EXPOSE 5000
COPY --from=builder /opt/app/build ./build
# Define the command to run the application
CMD ["sh", "-l", "-c", "npm run serve"]
CMD ["sh", "-l", "-c", "npm run serve"]

0 comments on commit 52b1b04

Please sign in to comment.