From faa27ae8903b194e02ea5733477000605f0fdac9 Mon Sep 17 00:00:00 2001 From: wvl94 Date: Wed, 28 Aug 2024 22:48:22 +0200 Subject: [PATCH 1/3] docker version update --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8d9c265..ea9c593 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,11 @@ -FROM node:19-alpine -ENV PORT 8080 +FROM node:20-alpine + WORKDIR /usr/src/app RUN apk add --no-cache git COPY . . + +ENV PORT 8080 EXPOSE 8080 CMD ["npm", "start", "--no-update-notifier"] \ No newline at end of file From 75aa8859235de288ec6986e3c5ff42a64f0be168 Mon Sep 17 00:00:00 2001 From: wvl94 Date: Wed, 28 Aug 2024 22:48:33 +0200 Subject: [PATCH 2/3] docker version update --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ea9c593..f86662c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:14-alpine WORKDIR /usr/src/app From c390307f8f6f69bd05ab979bdc9d799a3ad3b486 Mon Sep 17 00:00:00 2001 From: firstmate Date: Thu, 12 Sep 2024 09:52:52 +0000 Subject: [PATCH 3/3] Optimize Dockerfile with multi-stage build and non-root user --- Dockerfile | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index f86662c..2f6d643 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,30 @@ -FROM node:14-alpine - +# Stage 1: Build Stage +FROM node:14-alpine AS build WORKDIR /usr/src/app -RUN apk add --no-cache git +# Install dependencies +COPY package*.json ./ +RUN npm install + +# Copy the rest of the application files COPY . . +# Stage 2: Final Stage +FROM node:14-alpine + +WORKDIR /usr/src/app + +# Copy built files from the build stage +COPY --from=build /usr/src/app . + +# Create a non-root user +RUN addgroup -S appgroup && adduser -S appuser -G appgroup + +# Switch to the non-root user +USER appuser + ENV PORT 8080 EXPOSE 8080 + CMD ["npm", "start", "--no-update-notifier"] \ No newline at end of file