Skip to content
This repository has been archived by the owner on Mar 2, 2025. It is now read-only.

Commit

Permalink
Add multistage build to backend, reducing size by about 4 MB
Browse files Browse the repository at this point in the history
  • Loading branch information
robiworks committed Dec 31, 2021
1 parent a783133 commit 38d24a2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
#########################################
# MULTI-STAGE BUILD CONTAINER - Builder #
#########################################

# Base image
FROM node:alpine
FROM node:alpine AS builder

# Make folder to put our files in
RUN mkdir -p /usr/src/app
RUN mkdir -p /usr/src/app/backend

# Set working directory so that all subsequent command runs in this folder
# Set working directory so that all subsequent commands run in this folder
WORKDIR /usr/src/app/backend

# Copy package json and install dependencies
# Copy package.json, package-lock.json and install dependencies
COPY package*.json ./
RUN npm ci

# Copy our app
COPY . .

############################################
# MULTI-STAGE BUILD CONTAINER - Production #
############################################

# Base image
FROM node:alpine

# Set working directory
WORKDIR /usr/src/app/backend

# Copy all required app files from builder to production container
COPY --from=builder /usr/src/app/backend/ ./

# Expose port to access server
EXPOSE 5000

Expand Down

0 comments on commit 38d24a2

Please sign in to comment.