From ad8d546b78ae8b5e12d5b3190dc64f4ea5e7b2ee Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 14 Nov 2022 22:39:57 +0100 Subject: [PATCH] Utilize Multi-stage building to reduce Image-size --- Dockerfile | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index ecda5d2..cf9ab67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,28 @@ -FROM node:16-alpine +# ---- Base ---- +FROM alpine:3 AS base # Create app directory WORKDIR /usr/src/app +# Copy project file +COPY package.json . + +# Install required apk-packages +RUN apk add --no-cache nodejs npm tcpdump + + +# ---- Dependencies ---- +FROM base AS dependencies + # Install app dependencies -COPY package*.json ./ -RUN npm install +RUN npm install --only=production -# remove development dependencies -RUN npm prune --production -# Install required apk-packages & delete cache -RUN apk add --no-cache tcpdump +# ---- Release ---- +FROM base AS release +# copy from build image +COPY --from=dependencies /usr/src/app/ ./ # Bundle app source COPY ./src/ .