Architecture Overview
Docker deployment includes:
- 2 Database containers: MySQL 8.0, PostgreSQL 15
- 11 Spring Boot services: Config, Registry, Gateway + 8 microservices
- 1 Angular frontend: Nginx-served static files
- Docker network: Internal service communication
Prerequisites
Ensure Docker and Docker Compose are installed:
- Docker Engine 20.10+
- Docker Compose 2.0+
- 8GB RAM minimum
- 20GB free disk space
Verify Docker Installation
Project Structure
Create Dockerfiles
Step 1: Backend Service Dockerfile Template
CreateDockerfile in each Spring Boot service directory:
- Spring Boot 3.x Services
- Spring Boot 2.5.4 (Auth)
- Config & Registry Servers
Dockerfile
Step 2: Frontend Dockerfile
sistema-ventas-frontend/Dockerfile
Step 3: Nginx Configuration for Frontend
sistema-ventas-frontend/nginx.conf
Docker Compose Configuration
Step 4: Create docker-compose.yml
docker-compose.yml
Step 5: Environment Variables File
.env
Docker Profile Configuration
Create Docker-specific configuration inconfig-data/ directory:
config-data/application-docker.yml
Deployment Steps
Step 6: Build and Start Services
Management Commands
View Status
View Logs
Restart Services
Stop and Remove
Scaling Services
Scale business services for load balancing:Production Deployment
Step 7: Production docker-compose Override
docker-compose.prod.yml
Backup and Restore
Database Backup
Database Restore
Monitoring
Container Health
Resource Monitoring
Troubleshooting
Container fails to start
Container fails to start
Issue: Service container exits immediatelySolutions:
Database connection failed
Database connection failed
Issue: Services can’t connect to MySQL/PostgreSQLSolutions:
- Verify databases are healthy:
- Check database logs:
- Wait for database initialization (can take 60 seconds)
- Verify environment variables in docker-compose.yml
Service not registering with Eureka
Service not registering with Eureka
Issue: Microservices don’t appear in Eureka dashboardSolutions:
- Check registry-server is healthy
- Verify EUREKA_URI environment variable
- Check service logs for connection errors
- Wait 60 seconds for registration
- Restart service:
docker-compose restart service-name
Out of memory errors
Out of memory errors
Issue:
java.lang.OutOfMemoryError in logsSolutions:Build fails with dependency errors
Build fails with dependency errors
Issue: Maven build fails during docker buildSolutions:
Docker Compose Useful Commands
CI/CD Integration
GitHub Actions Example
.github/workflows/docker-deploy.yml
Best Practices
- Use multi-stage builds to reduce image size
- Implement health checks for all services
- Use Docker volumes for persistent data
- Set resource limits in production
- Use Docker secrets for sensitive data
- Enable logging drivers for centralized logs
- Implement backup strategy for databases
- Use Docker networks for service isolation
- Tag images with version numbers
- Monitor container resource usage
Next Steps
Monitoring & Logging
Set up monitoring with Prometheus and Grafana
API Documentation
Explore API endpoints and integrations