Docker Integration

Complete containerization solution for JAngular applications with Docker Compose, multi-stage builds, and production-ready deployment configurations.

JAngular provides comprehensive Docker integration with optimized containerization for all application components. The Docker setup includes multi-stage builds, persistent data storage, service orchestration, and production-ready configurations for seamless deployment across environments.

Containerized Architecture

The JAngular Docker setup consists of a complete microservices architecture with the following containerized components:

Core Application Services

  • Backend Service - Spring Boot application with Eclipse Temurin JDK 21
  • Frontend Service - Angular application served through Nginx with optimized static content delivery
  • Reverse Proxy - Nginx-based routing and load balancing for production deployments

Database Services

  • MySQL 8.0+ - High-performance relational database with InnoDB storage engine
  • PostgreSQL 15+ - Advanced open-source database with JSON support and performance optimizations
  • Microsoft SQL Server 2019+ - Enterprise database for Windows-based environments

Database Management Tools

  • phpMyAdmin - Web-based MySQL administration interface
  • pgAdmin 4 - PostgreSQL administration and development platform
  • SQL Server Management Studio (SSMS) - Microsoft SQL Server administration tools

Docker CLI Management

The JAngular CLI provides an interactive Docker management interface for easy container orchestration:

Interactive Docker Menu

jangular docker

This command launches an interactive menu with the following capabilities:

Service Management

  • Start All Services - Launch complete application stack with one command
  • Stop All Services - Gracefully shutdown all containers
  • Start Specific Services - Launch individual components (database, backend, frontend)
  • Restart Services - Restart containers with configuration changes

Monitoring & Diagnostics

  • View Service Logs - Real-time log streaming for all or specific services
  • Check Database Health - Database connectivity and performance checks
  • Container Status - Monitor container health and resource usage
  • Network Diagnostics - Inter-service communication testing

Data Management

  • Reset Volumes - Clean database volumes and reset to initial state
  • Backup Data - Create persistent backups of database volumes
  • Import/Export - Database migration and seeding utilities

Deployment Options

  • Development Mode - Hot reload enabled with debug configurations
  • Production Mode - Optimized builds with security hardening
  • Testing Mode - Isolated environment for automated testing

Multi-Stage Docker Builds

Optimized Docker builds using multi-stage architecture for minimal image sizes and enhanced security:

Backend Build Configuration

# Stage 1: Build Environment
FROM eclipse-temurin:21-jdk-jammy AS build
WORKDIR /app
COPY pom.xml .
COPY .mvn .mvn
COPY mvnw .
RUN chmod +x mvnw
COPY src ./src
RUN ./mvnw clean package -DskipTests

# Stage 2: Runtime Environment
FROM eclipse-temurin:21-jre-jammy
RUN groupadd -r spring && useradd -r -g spring spring
USER spring:spring
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD curl -f http://localhost:8080/actuator/health || exit 1

ENTRYPOINT ["java", "-jar", "app.jar"]

Frontend Build Configuration

# Stage 1: Build Environment
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production && npm cache clean --force
COPY . .
RUN npm run build --prod

# Stage 2: Web Server
FROM nginx:alpine
RUN addgroup -g 1001 -S nginx && adduser -S nginx -u 1001
COPY --from=build /app/dist/frontend/browser /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
COPY nginx-default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD wget --no-verbose --tries=1 --spider http://localhost/ || exit 1

CMD ["nginx", "-g", "daemon off;"]

Build Optimizations

  • Layer Caching - Optimized layer ordering for maximum cache efficiency
  • Multi-Architecture - Support for ARM64 and AMD64 architectures
  • Security Hardening - Non-root users and minimal attack surface
  • Health Checks - Built-in health monitoring for container orchestration

Docker Compose Orchestration

Comprehensive service orchestration with environment-specific configurations:

Development Configuration

# Start development environment
docker-compose up -d

# View aggregated logs
docker-compose logs -f

# View logs for specific service
docker-compose logs -f backend
docker-compose logs -f frontend
docker-compose logs -f mysql

# Stop all services
docker-compose down

# Stop and remove volumes (clean slate)
docker-compose down -v --remove-orphans

Production Configuration

# Deploy production environment
docker-compose -f docker-compose.prod.yml up -d

# Production health check
docker-compose -f docker-compose.prod.yml ps

# Scale services
docker-compose -f docker-compose.prod.yml up -d --scale backend=3

# Production shutdown
docker-compose -f docker-compose.prod.yml down

Service Dependencies

  • Startup Order - Database services start before application services
  • Health Dependencies - Applications wait for database readiness
  • Network Isolation - Services communicate through dedicated Docker networks
  • Volume Management - Persistent storage for databases and configuration

Environment Configuration

Flexible configuration management supporting multiple deployment scenarios:

Environment Variables

# Backend Environment
SPRING_PROFILES_ACTIVE=docker
SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/jangular
SPRING_DATASOURCE_USERNAME=jangular_user
SPRING_DATASOURCE_PASSWORD=secure_password
JWT_SECRET=your-production-jwt-secret
CORS_ALLOWED_ORIGINS=http://frontend:80

# Frontend Environment
ANGULAR_ENV=production
API_BASE_URL=http://backend:8080/api
AUTH_BASE_URL=http://backend:8080/auth

# Database Environment
MYSQL_ROOT_PASSWORD=root_password
MYSQL_DATABASE=jangular
MYSQL_USER=jangular_user
MYSQL_PASSWORD=secure_password

Configuration Files

  • .env - Development environment variables
  • .env.prod - Production environment variables
  • .env.test - Testing environment variables
  • docker-compose.override.yml - Local development overrides

Security Considerations

  • Secret Management - Docker secrets for sensitive configuration
  • Environment Isolation - Separate configurations per environment
  • Credential Rotation - Support for dynamic credential updates
  • Access Control - Network policies and service isolation

Persistent Storage & Volumes

Robust data persistence with backup and recovery capabilities:

Volume Configuration

  • Database Volumes - Persistent storage for database files
  • Configuration Volumes - Application configuration and secrets
  • Log Volumes - Centralized logging and audit trails
  • Upload Volumes - User-generated content storage

Backup Strategy

# Database backup
docker-compose exec mysql mysqldump -u root -p jangular > backup.sql

# Volume backup
docker run --rm -v jangular_mysql_data:/data -v $(pwd):/backup \
  alpine tar czf /backup/mysql-backup.tar.gz /data

# Restore from backup
docker run --rm -v jangular_mysql_data:/data -v $(pwd):/backup \
  alpine tar xzf /backup/mysql-backup.tar.gz -C /

Data Management

  • Volume Snapshots - Point-in-time backup creation
  • Data Migration - Cross-environment data transfer
  • Cleanup Procedures - Safe volume removal and cleanup
  • Storage Monitoring - Disk usage and performance metrics

Production Deployment

Enterprise-ready deployment with advanced orchestration and monitoring:

Production Features

  • SSL/TLS Termination - Automatic certificate management with Let's Encrypt
  • Load Balancing - Multi-instance backend scaling with health checks
  • Reverse Proxy - Nginx-based traffic routing and caching
  • Resource Limits - Memory and CPU constraints for optimal performance
  • Health Monitoring - Comprehensive health checks and alerting
  • Log Aggregation - Centralized logging with structured output

Production Commands

# Production deployment
docker-compose -f docker-compose.prod.yml up -d

# Scale backend services
docker-compose -f docker-compose.prod.yml up -d --scale backend=3

# Rolling updates
docker-compose -f docker-compose.prod.yml up -d --force-recreate backend

# Monitor production health
docker-compose -f docker-compose.prod.yml ps
docker-compose -f docker-compose.prod.yml top

Monitoring & Observability

  • Health Endpoints - Application and database health monitoring
  • Metrics Collection - Performance metrics and resource usage
  • Log Analysis - Error tracking and performance analysis
  • Alerting - Automated notifications for critical issues

Database Integration

Comprehensive database support with administration tools and health monitoring:

Database Health Checks

# MySQL health check
docker-compose exec mysql mysqladmin ping -h localhost -u root -p

# PostgreSQL health check
docker-compose exec postgres pg_isready -U postgres

# SQL Server health check
docker-compose exec mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P password -Q "SELECT @@VERSION"

Database Administration

  • Web Interfaces - Browser-based database management
  • Migration Tools - Automated schema migration and seeding
  • Performance Monitoring - Query analysis and optimization tools
  • Backup Automation - Scheduled backup and retention policies

Connection Management

  • Connection Pooling - Optimized database connection management
  • SSL Encryption - Secure database communications
  • Access Control - Role-based database access permissions
  • Network Isolation - Database network security and isolation

Production Note: The Docker configuration includes comprehensive security hardening, performance optimization, and monitoring capabilities suitable for enterprise production environments.