Overview
Crafter LoL uses multi-stage Docker builds for efficient containerization of both backend and frontend.Multi-stage builds reduce final image size by separating build dependencies from runtime dependencies.
Backend Dockerfile
Located atsource/Back/crafter/Dockerfile:
Stage 1: Build
Base Image: maven:3.9.6-eclipse-temurin-17
Base Image: maven:3.9.6-eclipse-temurin-17
- Maven 3.9.6: Build tool
- Eclipse Temurin 17: OpenJDK distribution
- Size: ~700MB (discarded after build)
Dependency Caching Strategy
Dependency Caching Strategy
pom.xml first and downloading dependencies before copying source code, dependencies are only re-downloaded when pom.xml changes.Benefits:- Faster builds (deps cached)
- Reduced bandwidth usage
Skip Tests in Build
Skip Tests in Build
-DskipTests: Skip test execution (compile but don’t run)-B: Batch mode (non-interactive, no download progress)
Stage 2: Runtime
Base Image: eclipse-temurin:17-jre-alpine
Base Image: eclipse-temurin:17-jre-alpine
- JRE only (no JDK/Maven): Smaller image
- Alpine Linux: Minimal Linux distribution (~5MB)
- Final image size: ~200MB (vs 700MB with full JDK)
JVM Flags Explained
JVM Flags Explained
- JVM metaspace
- Native memory
- OS overhead
Why ENTRYPOINT over CMD?
Why ENTRYPOINT over CMD?
ENTRYPOINT makes the container behave like an executable:Arguments are appended to ENTRYPOINT. With CMD, arguments would replace the entire command.
Building Backend Image
Build Docker Image
First build takes 2-3 minutes. Subsequent builds with cached dependencies: ~30 seconds.
Running Backend Container
Basic Run
Port mapping:
host:container- Host port 5000 maps to container port 5000
- Access at
http://localhost:5000
With Environment Variables
Production Run with Resource Limits
-d (Detached Mode)
-d (Detached Mode)
Runs container in background. View logs with:
--memory and --cpus
--memory and --cpus
Resource limits prevent container from consuming all host resources:
--memory="512m": Maximum 512MB RAM--cpus="1.0": Maximum 1 CPU core
MaxRAMPercentage=75.0, JVM heap will be ~384MB.--restart unless-stopped
--restart unless-stopped
Restart policy:
- Container restarts on failure
- Does NOT restart if manually stopped
- Survives host reboots
Frontend Dockerfile
Createsource/Front/Crafter_League_of_Legends/Dockerfile:
Nginx Configuration
Createsource/Front/Crafter_League_of_Legends/nginx.conf:
Building Frontend Image
Docker Compose
Createdocker-compose.yml in project root:
Usage
Health Checks
Health check configuration ensures container is actually serving traffic:(healthy) in the STATUS column.
Production Considerations
Use Specific Version Tags
Use Specific Version Tags
Non-Root User
Non-Root User
Add security by running as non-root:
Multi-Architecture Builds
Multi-Architecture Builds
Build for ARM and x86:
Secret Management
Secret Management
Never hardcode secrets in Dockerfile. Use:
- Environment variables
- Docker secrets
- External secret management (Vault, AWS Secrets Manager)
Debugging Containers
Next Steps
Production Deployment
Deploy to cloud platforms
Environment Configuration
Configure for different environments