From 38d24a28ec3ceb0606aefc599223bc5384ab1c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Samard=C5=BEija?= Date: Fri, 31 Dec 2021 15:31:22 +0100 Subject: [PATCH] Add multistage build to backend, reducing size by about 4 MB --- backend/Dockerfile | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index ab5b3e3..a87ca25 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -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