Skip to content
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

Dockerfile: reduce karmada website container image size by 28% #771

Open
wants to merge 1 commit into
base: main
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
36 changes: 23 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
FROM node:18-alpine
# Stage 1: Build Stage.
FROM node:18-alpine AS build

# Set working directory
WORKDIR /app/docs
# Set working directory.
WORKDIR /app

# Copy package.json and package-lock.json to the container
# Copy package.json and package-lock.json to the container.
COPY package.json package-lock.json ./

# Install dependencies
RUN npm install
# Install dependencies and browser-sync globally.
RUN npm install && npm install -g browser-sync

# Copy current directory to the container
# Copy the rest of the application files.
COPY . .

# Set environment variable
ENV NODE_ENV=development
# Stage 2: Development Stage.
FROM alpine:latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that the final image is based on alpine:latest, and node:18-alpine was used before. Does it matter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no problem, after the build is successful, it is indeed not necessary to continue using the node environment, and it can be replaced with the more streamlined alpine.

Copy link
Author

@mohamedawnallah mohamedawnallah Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that the final image is based on alpine:latest, and node:18-alpine was used before. Does it matter?

@XiShanYongYe-Chang I just noticed this notification—sorry for the delay! 🙏

For reference, the image sizes on linux/amd64 are:

That's about a 92% decrease in size.


# Install yarn in the final image required to run the application.
RUN apk add --no-cache yarn

# Set working directory.
WORKDIR /app

# Install browser-sync globally
RUN npm install -g browser-sync
# Copy only necessary files from the build stage (node_modules and app files).
COPY --from=build /app /app

# Set environment variable.
ENV NODE_ENV=development

# Expose port 3000
# Expose port 3000.
EXPOSE 3000

# Start the application
# Start the application using yarn.
CMD ["yarn", "run", "start:watch"]