Docker Setup for Docusaurus
This guide explains how to build and run the Docusaurus documentation site using Docker.
๐ณ Prerequisitesโ
- Docker installed (version 20.10+)
- Docker Compose installed (version 2.0+)
Check versions:
docker --version
docker-compose --version
๐ Quick Startโ
Development Mode (Hot Reload)โ
cd docs
docker-compose --profile dev up
Visit: http://localhost:3000/mcp-adr-analysis-server/
Changes to markdown files will auto-reload! ๐ฅ
Production Mode (Nginx)โ
cd docs
docker-compose --profile prod up --build
Visit: http://localhost:8080/mcp-adr-analysis-server/
Build Only (Test Build)โ
cd docs
docker-compose --profile build up --build
Output will be in build/
directory.
๐ Docker Commandsโ
Developmentโ
# Start dev server with hot reload
docker-compose --profile dev up
# Start in background
docker-compose --profile dev up -d
# View logs
docker-compose --profile dev logs -f
# Stop
docker-compose --profile dev down
Productionโ
# Build and run production server
docker-compose --profile prod up --build
# Run in background
docker-compose --profile prod up -d
# Stop
docker-compose --profile prod down
Rebuildโ
# Force rebuild (no cache)
docker-compose --profile dev build --no-cache
# Rebuild specific service
docker-compose build docusaurus-dev
๐ง Docker Architectureโ
Multi-Stage Dockerfileโ
The Dockerfile uses 3 stages:
-
Builder Stage (
builder
)- Installs dependencies
- Builds static site
- Output:
build/
directory
-
Production Stage (
production
)- Nginx Alpine image
- Serves built files
- Optimized for performance
-
Development Stage (
development
)- Node.js Alpine image
- Hot reload enabled
- Volume mounts for live editing
Docker Compose Profilesโ
dev
- Development server (port 3000)prod
- Production server (port 8080)build
- Build only (no server)
๐ File Structureโ
docs/
โโโ Dockerfile # Multi-stage build
โโโ docker-compose.yml # Service orchestration
โโโ nginx.conf # Nginx configuration
โโโ .dockerignore # Exclude files from build
โโโ DOCKER_SETUP.md # This guide
๐ฏ Use Casesโ
1. Local Developmentโ
Best for: Writing documentation with live preview
docker-compose --profile dev up
Features:
- Hot reload on file changes
- Fast feedback loop
- No local Node.js required
2. Production Testingโ
Best for: Testing final build before deployment
docker-compose --profile prod up --build
Features:
- Nginx serving (production-like)
- Gzip compression
- Security headers
- Asset caching
3. CI/CD Integrationโ
Best for: Automated builds in pipelines
docker-compose --profile build up --build
Features:
- Build verification
- Output artifacts
- No server overhead
๐ Troubleshootingโ
Port Already in Useโ
Development (3000):
# Change port in docker-compose.yml
ports:
- "3001:3000" # Use 3001 instead
Production (8080):
# Change port in docker-compose.yml
ports:
- "8081:80" # Use 8081 instead
Build Errorsโ
# Clear Docker cache
docker-compose down
docker system prune -a
# Rebuild from scratch
docker-compose --profile dev build --no-cache
Volume Permission Issuesโ
# Fix permissions (Linux/Mac)
sudo chown -R $USER:$USER .
# Or run with user flag
docker-compose --profile dev up --user $(id -u):$(id -g)
Container Won't Startโ
# Check logs
docker-compose --profile dev logs
# Check running containers
docker ps -a
# Remove old containers
docker-compose down -v
๐ข Deployment Workflowsโ
Local Testing Workflowโ
# 1. Develop with hot reload
docker-compose --profile dev up
# 2. Test production build
docker-compose --profile prod up --build
# 3. Verify everything works
# Visit http://localhost:8080/mcp-adr-analysis-server/
# 4. Push to GitHub (triggers GitHub Actions)
git add .
git commit -m "docs: Update documentation"
git push origin main
CI/CD Testingโ
# In GitHub Actions or CI pipeline
cd docs
docker-compose --profile build up --build
# Verify build succeeded
if [ -d "build" ]; then
echo "โ
Build successful"
else
echo "โ Build failed"
exit 1
fi
๐ Performance Optimizationโ
Nginx Configurationโ
The nginx.conf
includes:
- โ Gzip compression
- โ Static asset caching (1 year)
- โ Security headers
- โ Client-side routing support
Docker Image Sizeโ
- Development: ~400MB (includes dev dependencies)
- Production: ~50MB (Alpine + Nginx + static files)
Build Speedโ
# Use BuildKit for faster builds
DOCKER_BUILDKIT=1 docker-compose build
# Or set in environment
export DOCKER_BUILDKIT=1
๐ Securityโ
Nginx Security Headersโ
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Best Practicesโ
- โ Multi-stage builds (smaller images)
- โ Alpine base images (minimal attack surface)
- โ No root user in containers
- โ .dockerignore (exclude sensitive files)
- โ Security headers in Nginx
๐จ Customizationโ
Change Portsโ
Edit docker-compose.yml
:
services:
docusaurus-dev:
ports:
- "3001:3000" # Change 3001 to your port
Add Environment Variablesโ
services:
docusaurus-dev:
environment:
- NODE_ENV=development
- CUSTOM_VAR=value
Custom Nginx Configโ
Edit nginx.conf
for:
- Custom headers
- Proxy settings
- SSL/TLS configuration
- Rate limiting
๐ Additional Resourcesโ
โ Verification Checklistโ
After Docker setup:
- Development server runs:
docker-compose --profile dev up
- Hot reload works (edit a .md file)
- Production build succeeds:
docker-compose --profile prod up --build
- Production site accessible at http://localhost:8080
- All pages load correctly
- Navigation works
- Search functionality works
- Static assets load (images, CSS, JS)
๐ Success!โ
Your Docusaurus documentation is now running in Docker!
Quick Commands:
# Development
docker-compose --profile dev up
# Production
docker-compose --profile prod up --build
# Stop all
docker-compose down
Need Help? Check the Docusaurus Migration Guide or Quick Start Guide.