Skip to content

💡[Feature]: Optimize Dockerfile for Production with Multi-stage Build #1869

@shyam-medh

Description

@shyam-medh

Is there an existing issue for this?

  • I have searched the existing issues

Feature Description

Currently, the Dockerfile in the repository is set up primarily for development. It labels itself as a builder but copies all source code and runs npm run dev directly. This results in a very large Docker image that includes dev dependencies and source files.

I would like to implement a true multi-stage Docker build:

  1. Stage 1 (Builder): Use the Node.js image to install dependencies (npm ci) and build the Docusaurus static files (npm run build).
  2. Stage 2 (Production): Use a lightweight web server image (nginx:alpine), copy only the compiled static files from the builder stage, and serve them.

Additionally, I will update the docker-compose.yml to explicitly target the builder stage so that local development with hot-reloading (npm run dev) continues to work seamlessly.

Use Case

This feature enhances the project infrastructure by making it production-ready. Anyone looking to deploy the recode-website to a cloud provider (like AWS, DigitalOcean, or Azure) using Docker will benefit from a highly optimized, fast, and secure image.

Benefits

  1. Massive Reduction in Image Size: By dropping the source code and node_modules from the final image, the container size will drop significantly.
  2. Better Security: The final container will only contain static files and an Nginx server, eliminating Node.js runtime vulnerabilities in production.
  3. Improved Performance: Serving static files via Nginx is much faster and more efficient than running a Node.js development server (npm run dev) in production.

Add ScreenShots

No response

Priority

High

Record

  • I have read the Contributing Guidelines
  • I want to work on this issue
  • I am a part of gssoc26

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    Status
    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions