docker-compose.yml
The project includes a complete Docker Compose configuration:Services Explained
MySQL Service
Stores player statistics and ranking data. Configuration:- Image:
mysql:8.0 - Port Mapping: Host port
3307→ Container port3306- Uses 3307 on host to avoid conflicts with local MySQL installations
- Database: Automatically creates
blackjackdatabase - Credentials:
- Root password:
root - User:
blackjack - Password:
blackjack
- Root password:
- Persistence: Data is stored in
mysql_datanamed volume - Health Check: Waits up to 100 seconds (20 retries × 5s interval) for MySQL to be ready
MongoDB Service
Stores game state, deck, and hands. Configuration:- Image:
mongo:7 - Port Mapping: Host port
27017→ Container port27017 - Persistence: Data is stored in
mongo_datanamed volume - Health Check: Uses
mongoshto verify the database is responding
API Service
The main Spring Boot application. Configuration:- Image:
ccasr/blackjack-api:latest(pre-built from Docker Hub) - Port Mapping: Host port
8080→ Container port8080 - Environment: Uses
dockerprofile which configures:- MongoDB URI:
mongodb://mongo:27017/blackjack - MySQL connection:
r2dbc:mysql://mysql:3306/blackjack
- MongoDB URI:
- Dependencies: Waits for both MySQL and MongoDB health checks before starting
Starting the Stack
Start all services in detached mode:Stopping the Stack
Stop all services:Managing Services
View Running Services
Restart a Service
View Service Logs
Execute Commands in Services
Environment Variables
Docker Profile Configuration
WhenSPRING_PROFILES_ACTIVE=docker, the API uses these settings (from application-docker.yml):
Custom Environment Variables
You can override settings by adding environment variables to theapi service:
Data Persistence
Named Volumes
Docker Compose creates two named volumes:mysql_data- MySQL database filesmongo_data- MongoDB database files
Inspect Volumes
Backup Data
MySQL Backup
MongoDB Backup
Restore Data
MySQL Restore
MongoDB Restore
Health Checks
The compose file includes health checks for databases:MySQL Health Check
MongoDB Health Check
Testing the Stack
Once all services are running:1. Check Service Health
2. Test API Endpoints
3. Access Swagger UI
Open in your browser:4. Verify Database Connections
Troubleshooting
Container Won’t Start
Check logs:Database Connection Issues
Verify databases are healthy:Port Already in Use
Change host port indocker-compose.yml:
Reset Everything
Stop and remove all containers, volumes, and networks:Production Considerations
Security
For production deployments:- Change Default Passwords: Don’t use default credentials
- Use Secrets: Store credentials in Docker secrets or environment files
- Network Isolation: Use custom networks to isolate services
- Remove Port Bindings: Don’t expose database ports externally
Example Production Configuration
Next Steps
- Docker Deployment - Build custom Docker images
- Cloud Deployment - Deploy to production platforms