A comprehensive demonstration of containerizing a modern React.js application using Docker for both development and production workflows. This project showcases industry best practices for front-end containerization, including secure builds, streamlined development workflows, and optimized production delivery.
Part of the official Docker React.js sample guide.
- π₯ Modern React 19 with TypeScript
- β‘ Vite for lightning-fast development
- π¨ Tailwind CSS for utility-first styling
- π³ Multi-stage Docker builds for optimized production images
- π§ Development & Production Docker configurations
- π§ͺ Testing setup with Vitest and Testing Library
- π¦ Docker Compose for easy orchestration
- βΈοΈ Kubernetes deployment configuration
- οΏ½οΈ Secrurity-focused with vulnerability scanning
- π ESLint for code quality
- Frontend: React 19, TypeScript, Tailwind CSS
- Build Tool: Vite
- Testing: Vitest, React Testing Library
- Containerization: Docker, Docker Compose
- Orchestration: Kubernetes (optional)
- Web Server: Nginx (production)
- Docker (v20.10+)
- Docker Compose (v2.0+)
- Node.js (v18+) - for local development
- npm or yarn - for local development
-
Clone the repository
git clone https://github.com/kristiyan-velkov/docker-reactjs-sample.git cd docker-reactjs-sample -
Development with Docker Compose
docker compose up --build
Access the app at http://localhost:3000
-
Production build
docker build -t react-docker-app . docker run -p 8080:80 react-docker-appAccess the app at http://localhost:8080
-
Install dependencies
npm install
-
Start development server
npm run dev
-
Run tests
npm test -
Build for production
npm run build
# Build development image
docker build -f Dockerfile.dev -t react-app-dev .
# Run development container
docker run -p 3000:3000 -v $(pwd):/app react-app-dev
# Using Docker Compose (recommended)
docker compose up --build# Build production image
docker build -t react-app-prod .
# Run production container
docker run -p 8080:80 react-app-prod
# Multi-platform build
docker buildx build --platform linux/amd64,linux/arm64 -t react-app .Deploy to Kubernetes using the provided configuration:
kubectl apply -f reactjs-sample-kubernetes.yamlThis creates:
- Deployment with 3 replicas
- Service (LoadBalancer)
- ConfigMap for Nginx configuration
βββ public/ # Static assets
βββ src/ # Source code
β βββ components/ # React components
β βββ index.css # Global styles
β βββ main.tsx # Application entry point
βββ images/ # Documentation images
βββ Dockerfile # Production Docker configuration
βββ Dockerfile.dev # Development Docker configuration
βββ compose.yaml # Docker Compose configuration
βββ nginx.conf # Nginx configuration for production
βββ reactjs-sample-kubernetes.yaml # Kubernetes deployment
βββ Taskfile.yml # Task automation
Run the test suite:
# Local testing
npm test
# Testing in Docker
docker compose exec app npm testThis Docker image has been thoroughly scanned for vulnerabilities using Docker Scout and other security tools. The image passes all vulnerability assessments and follows security best practices:
- Non-root user execution
- Minimal base images (Alpine Linux)
- Regular dependency updates
- Security-focused Nginx configuration
| Variable | Description | Default |
|---|---|---|
PORT |
Application port | 3000 |
NODE_ENV |
Environment mode | development |
Create a compose.override.yaml file for local customizations:
services:
app:
ports:
- "3001:3000" # Use different port
environment:
- CUSTOM_VAR=value| Command | Description |
|---|---|
npm run dev |
Start development server |
npm run build |
Build for production |
npm run preview |
Preview production build |
npm run lint |
Run ESLint |
npm test |
Run tests |
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Kristiyan Velkov
- LinkedIn: kristiyan-velkov
- Medium: @kristiyanvelkov
- Newsletter: Front-end World
If you find this project helpful, consider supporting my work:
Your support helps me continue creating valuable content for the community! π

