Skip to content

Conversation

@jianyun8023
Copy link
Contributor

📦 Add Docker Support with Multi-stage Build

Description

This PR adds comprehensive Docker support to the project, enabling easy containerization and deployment of the Next.js application. The implementation includes optimized multi-stage builds for production use.

Changes

  • Added Dockerfile with multi-stage build

    • Stage 1: Dependencies installation using npm ci
    • Stage 2: Application build with Next.js standalone output
    • Stage 3: Minimal production runtime with security hardening
    • Uses Node.js 20 Alpine for smaller image size
    • Runs as non-root user (nextjs:nodejs) for enhanced security
  • 🚀 Added GitHub Actions workflow (.github/workflows/docker-build.yml)

    • Automated Docker image building on push to main/master/dev branches
    • Supports semantic version tagging
    • Multi-platform builds (linux/amd64, linux/arm64)
    • Publishes to GitHub Container Registry (ghcr.io)
    • Build cache optimization using GitHub Actions cache
  • 🙈 Added .dockerignore file

    • Excludes unnecessary files from Docker build context
    • Reduces image size and build time
    • Prevents sensitive files from being included
  • ⚙️ Updated Next.js configuration

    • Enabled output: 'standalone' mode for optimized Docker deployment
    • Reduces final image size by bundling only necessary dependencies

Benefits

  • 🐳 Easy deployment using Docker containers
  • 📦 Optimized image size through multi-stage builds
  • 🔒 Enhanced security with non-root user execution
  • 🚀 Automated CI/CD pipeline for image builds
  • 🌍 Multi-platform support (AMD64 and ARM64)

Usage

Build locally:

docker build -t next-ai-draw-io .

Run container:

docker run -p 3000:3000 -e OPENAI_API_KEY=your_key next-ai-draw-io

Pull from registry (after merge):

docker pull ghcr.io/${{ github.repository }}:latest

Testing

  • Docker image builds successfully
  • Application starts and runs correctly in container
  • Environment variables are properly passed
  • Multi-platform builds work as expected
  • GitHub Actions workflow executes successfully

Notes

  • The standalone output mode requires Next.js 12.2+ (current version supports this)
  • Container exposes port 3000 by default
  • All environment variables should be passed at runtime (not build time)

@vercel
Copy link

vercel bot commented Dec 2, 2025

@jianyun8023 is attempting to deploy a commit to the dayuanjiang's projects Team on Vercel.

A member of the Team first needs to authorize it.

@DayuanJiang
Copy link
Owner

Thank you for your contribution, merged!

@DayuanJiang DayuanJiang merged commit 271f3b0 into DayuanJiang:main Dec 3, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants