Skip to content

kristiyan-velkov/docker-reactjs-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

61 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿณ Docker React.js Sample Project

License: MIT Docker React TypeScript Vite

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.

๐Ÿš€ Demo

React.js Docker Sample Application Demo

โœจ Features

  • ๐Ÿ”ฅ 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
  • ๐Ÿ”’ Security-focused with vulnerability scanning
  • ๐Ÿ“‹ ESLint for code quality
  • ๐Ÿค– Advanced CI/CD with GitHub Actions (see workflows)

๐Ÿ› ๏ธ Tech Stack

  • 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)

๐Ÿ“‹ Prerequisites

๐Ÿš€ Quick Start

Using Docker (Recommended)

  1. Clone the repository

    git clone https://github.com/kristiyan-velkov/docker-reactjs-sample.git
    cd docker-reactjs-sample
  2. Development with Docker Compose

    docker compose up --build

    Access the app at http://localhost:3000

  3. Production build

    docker build -t react-docker-app .
    docker run -p 8080:80 react-docker-app

    Access the app at http://localhost:8080

Local Development

  1. Install dependencies

    npm install
  2. Start development server

    npm run dev
  3. Run tests

    npm test
  4. Build for production

    npm run build

๐Ÿณ Docker Commands

Development

# 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

Production

# 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 .

โ˜ธ๏ธ Kubernetes Deployment

Deploy to Kubernetes using the provided configuration:

kubectl apply -f reactjs-sample-kubernetes.yaml

This creates:

  • Deployment with 3 replicas
  • Service (LoadBalancer)
  • ConfigMap for Nginx configuration

๐Ÿ“ Project Structure

โ”œโ”€โ”€ 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

๐Ÿงช Testing

Run the test suite:

# Local testing
npm run test

# Testing in Docker
docker compose exec app npm run test

๐Ÿ›ก๏ธ Security

This 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
Docker Scout Security Scan Results

๐Ÿ”ง Configuration

Environment Variables

Variable Description Default
PORT Application port 3000
NODE_ENV Environment mode development

Docker Compose Override

Create a compose.override.yaml file for local customizations:

services:
  app:
    ports:
      - "3001:3000" # Use different port
    environment:
      - CUSTOM_VAR=value

๐Ÿ“š Available Scripts

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

๐Ÿค Contributing

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Kristiyan Velkov

โ˜• Support

If you find this project helpful, consider supporting my work:

Your support helps me continue creating valuable content for the community! ๐Ÿš€

๐Ÿ”— Related Resources

About

A production-ready and developer-friendly Docker setup for modern React.js applications. Used in the official Docker React.js sample to demonstrate secure, efficient, and scalable front-end containerization.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors