Skip to content

Reduce final docker image size #4150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
### STAGE 0: Build client ###
FROM node:20-alpine AS build
FROM node:20-alpine AS build-client
WORKDIR /client
COPY /client /client
RUN npm ci && npm cache clean --force
RUN npm run generate

### STAGE 1: Build server ###
FROM node:20-alpine
FROM node:20-alpine AS build-server

ENV NODE_ENV=production

Expand All @@ -21,9 +21,9 @@ RUN apk update && \
tini \
unzip

COPY --from=build /client/dist /client/dist
COPY index.js package* /
COPY server server
WORKDIR /server
COPY index.js package* /server
COPY /server /server/server

ARG TARGETPLATFORM

Expand All @@ -42,7 +42,20 @@ RUN case "$TARGETPLATFORM" in \

RUN npm ci --only=production

RUN apk del make python3 g++
### STAGE 2: Create minimal runtime image ###
FROM node:20-alpine

# Install only runtime dependencies
RUN apk add --no-cache \
tzdata \
ffmpeg \
tini

WORKDIR /app

# Copy compiled frontend and server from build stages
COPY --from=build-client /client/dist /app/client/dist
COPY --from=build-server /server /app

EXPOSE 80

Expand Down